This community-built FAQ covers the “Escape Characters” exercise from the lesson “Introduction to Strings”.
Paths and Courses
This exercise can be found in the following Codecademy content:
Computer Science
FAQs on the exercise Escape Characters
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply ( ) below!
Agree with a comment or answer? Like ( ) to up-vote the contribution!
Need broader help or resources ? Head here .
Looking for motivation to keep learning? Join our wider discussions .
Learn more about how to use this guide.
Found a bug ? Report it!
Have a question about your account or billing? Reach out to our customer support team !
None of the above? Find out where to ask other questions here !
catower
Split this topic
December 28, 2019, 10:18pm
2
In this example, why are escape characters starting before the left insider quotation mark and ending before the right insider quotation mark, as in:
password = "theycallme(backslash)"crazy(backslash)“91”
but NOT:
password = “theycallme(backslash)“crazy”(backslash)91”
Why shouldn’t the escape character wrap the right quotation mark too? Pardon the fact I couldn’t use actual backslashes in the post as they don’t show up for some reason.
mtrtmk
April 3, 2024, 3:16am
5
To preserve code formatting in forum posts, see: How do I format code in my posts?
password = "theycallme\"crazy\"91"
password = "theycallme\"crazy"\91"
The backslash doesn’t escape a block of characters. It only escapes a single character.
In the first version, the first backslash will escape the quote before crazy
, whereas the second backslash will escape the quote after crazy
.
In the second version, the first backslash will escape the quote before crazy
, but the quote after crazy
will not be escaped.
So we are not trying to wrap "crazy"
with backslashes. Instead the backslash is supposed to be placed before the specific character we wish to escape.
1 Like