0% found this document useful (0 votes)
30 views2 pages

Python Escape Sequences Explained

The document provides a list of Python escape sequence characters along with examples of their usage. Each escape sequence is accompanied by a print statement that demonstrates its output. The document covers various characters such as backslash, single quote, double quote, new line, and others.

Uploaded by

arunimajoshi3110
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views2 pages

Python Escape Sequences Explained

The document provides a list of Python escape sequence characters along with examples of their usage. Each escape sequence is accompanied by a print statement that demonstrates its output. The document covers various characters such as backslash, single quote, double quote, new line, and others.

Uploaded by

arunimajoshi3110
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Python Escape Sequence Characters

\\ - Backslash

print("This is a backslash: \\\\") # Output: This is a backslash: \\

\' - Single quote

print(\'It\\\'s Python!\') # Output: It\'s Python!

\" - Double quote

print("She said: \\\"Hi!\\\"") # Output: She said: \"Hi!\"

\n - New line

print("Line1\\nLine2") # Output:\nLine1\nLine2

\t - Horizontal tab

print("Hello\\tWorld") # Output: Hello World

\r - Carriage return

print("12345\\rabc") # Output: abc45

\b - Backspace

print("abc\\bdef") # Output: abdef

\f - Form feed

print("abc\\fdef") # Output may vary, rarely used

\a - Bell (alert)

print("\\a") # May produce a beep sound


Python Escape Sequence Characters

\v - Vertical tab

print("abc\\vdef") # Output may vary, rarely used

\ooo - Octal value (e.g., \141 for 'a')

print("\\141") # Output: a

\xhh - Hex value (e.g., \x61 for 'a')

print("\\x61") # Output: a

You might also like