Python's Philosophy:
....
Simple is better than complex.
....
So why does it use both double quote " " and single quote ' ' to indicate something is a string literal.
I was lost when I typed:
x = "aa"
x
And saw:
'aa'
But not:
"aa"
When I saw the above philosophy, I doubted it. It needs some explanations.
This isn't complex at all. In fact, it's rather helpful.
Both '' and "" can be used in python. There's no difference, it's up to you.
In your example, when you type x, you are given the representation of the string (i.e, it's equivalent to print repr(x)). It wouldn't have mattered if you did x = 'aa'
I like to use either for cases such as:
print 'Bill said, "Hey!"'
print "I'm coming!"
If we used " for the first example, then there would be an error because Python would interpret it as "Bill said, ".
If we used ' for the second example, then there would be an error because Python would interpret it as 'I'
Of course, you could just escape the apostrophes, but beautiful is better than ugly.
You can use "" to be able to write "I'm legend" for example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With