Python

Python
Is there a difference from using ’ ’ from " " ?

If you want to avoid using escape characters if you have a ’ or " in your string, then use the opposite of whatever is in your string.

Playing with the terminal we find:

>>> 'hi'
'hi'
>>> 'h"i'
'h"i'
>>> "h'i"
"h'i"
>>> 'h'i'
  File "<stdin>", line 1
    'h'i'
       ^
SyntaxError: invalid syntax

>>> 'h\'i'  #using the "\" escape character
"h'i"

4 Likes

Thanks for your help!!

Just to add something else, there is multiline strings ("""), in case your string goes over many lines.

multiline_string="""
SEEE
SO
COOL
"""
1 Like

Yes! and i think you can also do it with the single ones for the same effect (''').

1 Like