Python
2: Escape Sequence
3: Comments
4: Escape Sequence as Normal Text
5: Print Emoji
6: Python as Calculator
7: Strings Concatenation
8: Input
9: int function
10: Variables
11: String Formatting
12: String Indexing
13: String Slicing
14: Step Argument
15: Some useful function and methods
16: Strip Method
17: Find and Replace method
Chapter 2: Escape Sequence
Escape Sequence | Meaning |
\’ | Single quote |
\" | Double quote |
\\ | Backslash |
\n | New line |
\t | Tab |
\b | backslash |
In Chapter 1, we learn that we can't use double quotes inside a print function that uses double quotes or single quotes inside a print function that uses single quotes. However, we can include double quotes inside a print function using double quotes and single quotes inside a print function using single quotes by utilizing escape sequences.
Escape sequences with example:
- \’ → This escape sequence allows us to use a single quote inside a print function that uses single quotes.
print('I\'m reading escape sequences in chapter two.')
Output: I'm reading escape sequences in chapter two.
- \” → This escape sequence allows us to use double quotes inside a print function that uses double quotes.
print("I'm reading \"escape sequences\" in chapter two.")
Output: I'm reading "escape sequences" in chapter two.
- \\ → This escape sequence is used to display a single backslash.
print("I'm using \\ backslash here \\")
Output: I'm using \ backslash here \
- \n → This escape sequence creates a new line.
print("This is line one. \n This is line two. \n This is line three.")
Output: This is line one.
This is line two.
This is line three.
- \t → This escape sequence inserts a tab space.
print("Website\tFree Learning")
Output: Website Free Learning
- \b → This escape sequence works as a backspace, removing the last character printed.
print("Removing character A\b using backslash escape sequence.")
Output: Removing character using backslash escape sequence.