Escape characters are characters that are generally used to perform certain tasks and their usage in code directs the compiler to take a suitable action mapped to that character.
'\n' --> Leaves a line '\t' --> Leaves a space
The string after resolving escape character is : I Love Geeksforgeeks
But in certain cases it is desired not to resolve escapes, i.e the entire unresolved string has
to be printed. These are achieved by following ways.
This function returns a string in its printable format, i.e doesn’t resolve the escape sequences.
The string without repr() is : I Love Geeksforgeeks The string after using repr() is : 'I\nLove\tGeeksforgeeks'
Adding “r” or “R” to the target string triggers a repr() to the string internally and stops from the resolution of escape characters.
The string without r/R is : I Love Geeksforgeeks The string after using r is : I\nLove\tGeeksforgeeks The string after using R is : I\nLove\tGeeksforgeeks
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Python - Escape reserved characters in Strings List
- html.escape() in Python
- Preventing Escape Sequence Interpretation in Python
- Python program to print k characters then skip k characters in a string
- Python | Ways to split a string in different ways
- Python | Ways to remove n characters from start of given string
- Python | Ways to check string contain all same characters
- Python | Ways to split strings on Uppercase characters
- Python | Convert list of strings and characters to list of characters
- Print lists in Python (4 Different Ways)
- Python | Ways to print list without quotes
- Python - Ways to print longest consecutive list without considering duplicates element
- Python code to print common characters of two Strings in alphabetical order
- How to print Odia Characters and Numbers using Python?
- Ways to sort list of dictionaries by values in Python - Using lambda function
- Ways to sort list of dictionaries by values in Python – Using itemgetter
- Different ways to access Instance Variable in Python
- Reverse string in Python (5 different ways)
- Ways to increment a character in Python
- Extending a list in Python (5 different ways)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.