+ 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

12th Jul 2018, 8:38 PM
Eliza Shoop
Eliza Shoop - avatar
7 ответов
+ 3
You have to escape it by putting a backslash before it like this: print 'It\'s friday!'
12th Jul 2018, 8:43 PM
Ben Allen (Njinx)
Ben Allen (Njinx) - avatar
+ 1
Eliza Shoop print(spam +"\' "+eggs)
12th Jul 2018, 8:50 PM
Dlite
Dlite - avatar
+ 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 \.
12th Jul 2018, 8:54 PM
HonFu
HonFu - avatar
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?
12th Jul 2018, 8:48 PM
Eliza Shoop
Eliza Shoop - avatar
0
thank you
12th Jul 2018, 8:51 PM
Eliza Shoop
Eliza Shoop - avatar
0
Eliza Shoop Thank you
12th Jul 2018, 8:51 PM
Dlite
Dlite - avatar
0
Eliza Shoop Look at the example again, you'll notice a difference
12th Jul 2018, 8:53 PM
Dlite
Dlite - avatar