-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3_escape_with_backslash.py
More file actions
43 lines (31 loc) · 1.2 KB
/
3_escape_with_backslash.py
File metadata and controls
43 lines (31 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# ==============================
# Python Escape Sequences Cheat Sheet
# =============================
# New line
print("Hello\nWorld") # Moves text after \n to the next line
# Tab space
print("Hello\tWorld") # Adds a horizontal tab between words
# Backslash
print("This is a backslash: \\") # Prints a single backslash
# Double backslash
print("This is a double backslash: \\\\") # Prints two backslashes
# Escaping quotes
print("She said \"Hello\"") # Double quotes inside a double-quoted string
print('It\'s a beautiful day') # Single quote inside a single-quoted string
# Carriage return (overwrites from start)
print("Hello\rWorld") # "World" replaces "Hello"
# Backspace (removes previous character)
print("Hello\bWorld") # Removes 'o' from Hello
# Unicode characters
print("Smile: \u263A") # Prints ☺
print("Heart: \u2764") # Prints ❤
# Octal and Hexadecimal
print("Octal: \110\145\154\154\157") # "Hello" in octal
print("Hex: \x48\x65\x6C\x6C\x6F") # "Hello" in hex
# Raw strings (no escaping)
print(r"C:\Users\Ankita\Documents") # Prints path as is
print("C:\\Users\\Ankita\\Documents")
# Triple-quoted strings (multiline)
print("""This is
a multi-line
string with no escapes needed""")