Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
5 views

Escape_Sequences_Python

The document explains various escape sequences in Python, including newline, tab, backslash, single and double quotes, carriage return, backspace, form feed, alert, vertical tab, and null character. Each escape sequence is illustrated with examples showing their output. Additionally, it mentions the raw string prefix which treats backslashes as literal characters.

Uploaded by

Vedansh Singh
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)
5 views

Escape_Sequences_Python

The document explains various escape sequences in Python, including newline, tab, backslash, single and double quotes, carriage return, backspace, form feed, alert, vertical tab, and null character. Each escape sequence is illustrated with examples showing their output. Additionally, it mentions the raw string prefix which treats backslashes as literal characters.

Uploaded by

Vedansh Singh
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
You are on page 1/ 2

Escape Sequences in Python

\n - Newline: Moves to the next line.

Example: print('Hello\nWorld') -> Output:

Hello

World

\t - Horizontal Tab: Inserts a tab space.

Example: print('Hello\tWorld') -> Output: Hello World

\\ - Backslash: Prints a backslash.

Example: print('This is a \\') -> Output: This is a \

\' - Single Quote: Inserts a single quote.

Example: print('It\'s sunny') -> Output: It's sunny

\" - Double Quote: Inserts a double quote.

Example: print('He said, \"Hi\"') -> Output: He said, "Hi"

\r - Carriage Return: Moves the cursor to the beginning of the line.

Example: print('Hello\rWorld') -> Output: World

\b - Backspace: Removes the previous character.

Example: print('Helloo\b') -> Output: Hello

\f - Form Feed: Advances to the next page in printers.

Example: print('Hello\fWorld')

\a - Bell/Alert: Triggers a sound (if supported by the system).

Example: print('\a')
\v - Vertical Tab: Inserts a vertical tab.

Example: print('Hello\vWorld')

\0 - Null Character: Represents a null character.

Example: print('Hello\0World') -> Output: Hello World

Raw String Prefix (r): Treats backslashes as literal characters.

Example: print(r'Hello\nWorld') -> Output: Hello\nWorld

You might also like