Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why use \' escape sequence instead of just '?

Tags:

python

Is there any difference between:

print "I am John Doe\'s cousin."

and:

print "I am John Doe's cousin."
like image 464
zencoder Avatar asked Nov 27 '25 22:11

zencoder


1 Answers

When you use the line with out the \' and if you wrote it using single quotation marks(an apostrophe) python would read the line as

print ('I am doe')

then would give an error because python doesn't expect anything after the apostrophe

when you use a backslash python takes the apostrophe as a string and not an end of string

when you use the regular quotation mark it doesn't matter, python will read it the same


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!