If both are valid, why would you use double or single quotes for any given string?
Answer
It depends on the string you’re writing or storing for sure. The important thing is to always have the same type of quote on the outside, and always have a closing outside quote for an opening outside quote.
If we need to write a string with an apostrophe in the middle, it’s best to use double quotes on the outside, otherwise it’ll think we have an extra quote!
See how the second example looks like we closed off our string after the ‘n’ in “doesn’t”?
Another common practice is using double quotes for strings and single quotes for single characters, like ‘n’.
There really is no set rule or reason to use one or the other. Personal preference will prevail. Needless, production environments in collaborative projects will prevail even further in what they dictate as best practice, style guidelines, etc.
Eg.
Generating HTML
$div = '<div class="item">' + item + '</div>'
The HTML on inspection has a double quoted attribute which is typical in HTML composition. I am actually a stickler about this one style guide recommendation. I love to see HTML attributes in double quotes when inspecting., The E. B. White approach.
In the next step we have to debug and when i add " to the string it comes twice like this “” and the comand executes an error what should i do to us only one on both of sides.
i tried but on the left side of the string it comes once while on ending it comes twice.
any solution???
Thanx for this answer.I also run this type of problem.
print"This looks, right doesn’t it?"-it easily run,
but,
print’This looks, right doesn’t it?’-it has problem of this type
(File “script.py”, line 7
print’This looks, right doesn’t it?’
^
SyntaxError: invalid syntax)