+ 3
I don't understand why the word "escape" is being used...what does it mean in reference to Python?
8 Réponses
+ 12
Well if you talk about string, there are some characters which cannot be used without an "escape" character... For example:
You have this string 'It's me'... The string will end before 's' because the computer thinks that this is where it is ending...
This problem can be fixed using an escape backslash.
'It\'s me'. Now the computer will read the quote as part of the string, and the second quote will end the string... Hope it makes sense :)
+ 10
@Tim You can use double quotes in single quptes strings or vice-versa 😂😂
+ 9
@Tim I was really tired and I saw single quotes to wrap the string instead of double quotes...
+ 6
Are you referring to escape sequences?
Say you have a string "He said "Hello" to the World."
The second and third quotes need to be escaped in order to not end the string. Thus, the proper way to do it would be as follows:
"He said \"Hello\" to the World."
You use the \ (backslash) to escape the character.
Otherwise, you'd receive a syntax error:
>>> "He said "hello" to me"
File "<stdin>", line 1
"He said "hello" to me"
^
SyntaxError: invalid syntax
>>> "He said \"Hello\" to me"
'He said "Hello" to me'
+ 4
@Scatterbrain Lady, I know how you feel. I felt the exact same way when I started out and had a ton of questions that when I think about now seem incredibly noob-ish😅. Just think of the word as if the escape characters are trying to "escape" the syntax error 😉.
Don't worry you won't be noob for long.
+ 3
@Nihar omg thanks...that's a great way to look at it
+ 2
@Gami
I'm aware, I was just using double quotes as an example since it's what I personally use for natural language strings, but everyone has their own style..
+ 2
@Tim no just the word itself. while reading I keep thinking something is trying to get away...it's just the first thing that comes to mind when I see the word "escape". I kinda understand what the function of the word means but don't understand why that word in particular is used to describe it. this is LITERALLY my first day with Python...so ima SUPER NOOB