example problem | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

example problem

>>> 'Brian\'s mother: He\'s not the Messiah. He\'s a very naughty boy!' 'Brian's mother: He's not the Messiah. He's a very naughty boy!'. i dont understand

24th Jan 2020, 7:31 PM
ifrit
2 Answers
+ 5
The lesson is teaching the use of escape characters when printing strings. In the sentence example there a 5 quotation marks. The outside quotation marks are meant to encapsulate the string sentence. The inner quote marks are for the English language syntax. Python will try to encapsulate the string from the first pair of quote marks, so to prevent this, an escape character is used (\) to tell Python to bypass the following quote mark. This continues to happen until a quote mark is encountered which has not been escaped. The string is then encapsulated. Try printing 'Brian's', Then try printing 'Brian\'s' You will see the difference in the output
24th Jan 2020, 7:51 PM
Rik Wittkopp
Rik Wittkopp - avatar
0
it was in the strings topic, i dnt understand if i have to remove \ from first line or i have to use \ where i will use 's ?
24th Jan 2020, 7:46 PM
ifrit