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
- Python | Ways to check string contain all same characters
- Python | Ways to remove n characters from start of given string
- Python | Ways to split strings on Uppercase characters
- Print lists in Python (4 Different Ways)
- Python | Ways to print list without quotes
- Python code to print common characters of two Strings in alphabetical order
- Python | Ways to split a string in different ways
- Python | Convert list of strings and characters to list of characters
- Python | Ways to Spilt the list by some value
- Python | Ways to concatenate tuples
- Extending a list in Python (5 different ways)
- Python | Ways to flatten a 2D list
- Ways to increment a character in Python
- Python | Different ways to kill a Thread
- Python | Ways to Copy Dictionary
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.