Robotics & Artificial Intelligence
What do you understand by escape character? Explain any five escape sequences used in Python with the help of examples.
Getting Started
2 Likes
Answer
An escape character is a special character used in a string to insert characters that cannot be written directly inside the string. In Python, the backslash (\) is used as an escape character. The combination of the backslash and another character is called an escape sequence.
Five escape sequences in Python:
1. \n (New line) — It is used to move the cursor to a new line.
Example:
print("Hello\nWorld")
Output:
Hello
World
2. \t (Tab space) — It is used to provide horizontal tab space in a string.
Example:
print("Python\tProgramming")
Output:
Python Programming
3. \' (Single quote) — It is used to insert a single quote inside a string.
Example:
print('It\'s my pen')
Output:
It's my pen
4. \" (Double quote) — It is used to insert a double quote inside a string.
Example:
print("He said, \"Hello\"")
Output:
He said, "Hello"
5. \\ (Backslash) — It is used to insert a backslash character in a string.
Example:
print("The symbol is \\")
Output:
The symbol is \
Answered By
3 Likes
Related Questions
What do you understand by gears in robots? Write about various types of gear. Write about various applications of gears in robotics.
What do you mean by mechanical block of a robot? What are the various components of mechanical block of a robot. What are the important applications of mechanical block of a robot?
What do you mean by machine learning? Explain the importance of data in machine learning with the help of an example.
How does a module helps in code reusability? Explain with the help of an example. Create a Python package and one module under it. Write a Python code to use this package.