Error for: ('I'm leaving!') Why? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Error for: ('I'm leaving!') Why?

Contractions

25th Jul 2017, 7:40 PM
suzi
10 Answers
+ 5
The other ways to put quotes in quotes, are: + 'escape' them (meaning warn Python that you put a quote inside the string literal, and that's not the closing quote marking the end of the string): print('I\'m leaving') the backslash (\) say to Python that next char is in string and not to be interpreted... So, to put backslash in a string literal, you need to escape it if just before an escapable char ^^ print('I\'m a backslash: \\') this work same for double quotes strings... + use triple quote (simple or double) notation, which allow also multilines strings (the only place were you cannot put same type of quote is just before ending triple quotes, as Python interpreter will considerate the first 3 as the 3 closing -- same limitation with backslash, but simple workaround by inserting a space at end of string before the closing quote(s) ^^) print('''This is a simple quote which doesn't need to be escaped...''')
26th Jul 2017, 6:18 AM
visph
visph - avatar
+ 3
You have the answer already but for the sake redundancy I'll tell you why it didn't work initially. Python is confused why you have 3 single quotes when it expected 2. That's because of the apostrophe in I'm. To fix this you either need to make the outside single quotes into double quotes ("...") or to keep everything the same except for I'm which you can fix by writing I\'m instead
25th Jul 2017, 8:06 PM
God Usopp
God Usopp - avatar
+ 2
What's the error? Maybe its the quotes, have you tried: ("I'm leaving!")
25th Jul 2017, 7:44 PM
Bagshot
Bagshot - avatar
+ 2
Ahh, that makes sense. Still new. I appreciate the help, being the newbie.
25th Jul 2017, 8:12 PM
suzi
+ 1
Could very well be. Those pesky inverted commas catch me out from time to time.
25th Jul 2017, 7:55 PM
Bagshot
Bagshot - avatar
+ 1
No problemo.
25th Jul 2017, 8:03 PM
Bagshot
Bagshot - avatar
+ 1
Put it way better than I could. Spot on, Usopp.
25th Jul 2017, 8:11 PM
Bagshot
Bagshot - avatar
0
I have not used quotes. I assumed the 'I'm' is the error in question.
25th Jul 2017, 7:47 PM
suzi
0
The quotes seem to work. I have much to learn. Thank you so much!
25th Jul 2017, 7:56 PM
suzi
0
Oh wow, Visph. I have so much to learn. Thank you (and God Usopp and Bashot) for giving me so much to play with here! I can\'t wait to keep devouring more info!!!
26th Jul 2017, 2:56 PM
suzi