What is an escape character? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is an escape character?

There is a question in python quiz saying which one of the followimg is an escape charater.Please tell me what exactly an escape character is.

3rd Feb 2021, 8:46 AM
Aditya
Aditya - avatar
6 Answers
+ 11
Escape characters are used for escape sequence from the string for it to be printed and also for special characters. We use backslash (\) to escape characters. Common examples are \n and \t which indicates new line and tab, respectively. It is also used for regular expressions: \w ---> word \d ---> digit etc. See this code for quick examples. https://code.sololearn.com/cRiJax343R7Y/?ref=app
3rd Feb 2021, 9:01 AM
noteve
noteve - avatar
+ 8
Often if you want to write '\' itself, you have to escape it with another '\' and write "\\"
3rd Feb 2021, 9:30 AM
Sonic
Sonic - avatar
+ 6
An Escape character is a character that starts an escape sequence in a string, that means a sequence that is not printed as it is written. For example: "\n" newline "\t" tab So '\' is an escape character
3rd Feb 2021, 9:01 AM
Angelo
Angelo - avatar
+ 4
It's a wand that gives the following character magic powers "n" on is own is just "n" \.-*-._.- "n" abra kadabra! ... boom! \n now n has the power to create a new line. 😁 but sometimes it can remove its magic powers
3rd Feb 2021, 9:18 AM
D_Stark
D_Stark - avatar
0
Regarding "\\", in stings where you don't want escaping sequences at all, you can use raw-strings (r"...") Useful in file paths and regex for example
3rd Feb 2021, 9:42 AM
Angelo
Angelo - avatar
0
Thank you guys I know this was a small question yet you told me the answer😸
3rd Feb 2021, 12:01 PM
Aditya
Aditya - avatar