Why does Python use ‘ instead of “
Question:
I don‘t know why Python uses '
instead of "
.
I mostly use Java and C# and there a '
is a char type.
Could anyone explain this to me?
Answers:
Python uses both. The reason being that if your string contains the character " (i.e. 'Sally said, "Hello there".'
), you would use ‘ to define your string, therefore eliminating the need to escape the " character. Conversely, if your string contains ‘ as a charater (i.e "John's Food"
), you would use " to remove the need to escape the ‘ character.
It’s a small quality of life thing over Java.
I don‘t know why Python uses '
instead of "
.
I mostly use Java and C# and there a '
is a char type.
Could anyone explain this to me?
Python uses both. The reason being that if your string contains the character " (i.e. 'Sally said, "Hello there".'
), you would use ‘ to define your string, therefore eliminating the need to escape the " character. Conversely, if your string contains ‘ as a charater (i.e "John's Food"
), you would use " to remove the need to escape the ‘ character.
It’s a small quality of life thing over Java.