+ 1
Python grammar (apostrophe) SOLVED
I’m having trouble finding the lesson where it tells me how to insert an apostrophe to a printed sentence in Python. Any help would be appreciated. I’ve just started to learn to code and I’m just trying to get the basics down right now. https://code.sololearn.com/cvZgC181yDip/?ref=app
7 ответов
+ 3
You have to escape it by putting a backslash before it like this:
print 'It\'s friday!'
+ 1
Eliza Shoop
print(spam +"\' "+eggs)
+ 1
You would have to write
spam+'\' s '+eggs
or if this is confusing for your eyes, you can use another set of quotation marks on the outside:
print("It's friday.")
This way, the single ' is read as a character without using that \.
0
Can that work with a variable?
If I put :
spam= ‘it’
eggs= ‘friday’
print (spam\’s + eggs)
would it allow me to do that?
0
thank you
0
Eliza Shoop
Thank you
0
Eliza Shoop Look at the example again, you'll notice a difference