Possible Duplicate:
Single quotes vs. double quotes in Python
I have seen that when i have to work with string in Python both of the following sintax are accepted:
mystring1 = "here is my string 1"
mystring2 = 'here is my string 2'
Is anyway there any difference?
Is it by any reason better use one solution rather than the other?
Cheers,
No, there isn’t. When the string contains a single quote, it’s easier to enclose it in double quotes, and vice versa. Other than this, my advice would be to pick a style and stick to it.
Another useful type of string literals are triple-quoted strings that can span multiple lines:
Again, it’s up to you whether to use single or double quotes for this.
Lastly, I’d like to mention “raw string literals”. These are enclosed in
r"..."orr'...'and prevent escape sequences (such as\n) from being parsed as such. Among other things, raw string literals are very handy for specifying regular expressions.Read more about Python string literals here.