Python Character Set
M3-R5.1 · Chapter 3: Introduction to Python · 3 min read
Python Character Set
A character set is a set of valid characters that a recognize (acceptable) by a programming language in scripting. Now, we are studying about the Python programming language. So, the Python character set is a valid set of characters recognized by the Python language and python follows the Unicode Character Set.
These are two type of character sets in python language. These are:
- Source Character
- Execution Characters/Escape Sequence
Source Character
- Alphabets: All capital (A-Z) and small (a-z) alphabets.
- Digits: All digits 0-9.
- Special Symbols: Python supports all kind of special symbols like, ” ‘ l ;: ! ~ @ # $ % ^ ` & * ( ) _ + – = { } [ ] \ .
- White Spaces: White spaces like tab space, blank space, newline, and carriage return.
- Other: python can process all ASCII and Unicode characters as part of data or literals
Execution Characters/Escape Sequences:
Python allows to have certain non-graphic characters in string values. These characters are interpreted at the time of execution. Such characters cannot be typed directly from keyboard. e.g. backspace, tabs, carriage return etc. These can be represented by escape sequence. An escape sequence is represented by backslash followed by one or more characters.
|
Execution Character |
Meaning |
Result at Execution Time |
|
\n |
End of the Line |
Move the active position to the initial position of the next line |
|
\t |
Horizontal Tab |
Move the active position to the next horizontal tabulation position |
|
\b |
Backspace |
Move the active position to the next previous position of the current line |
|
\a |
Alert |
Produces an audible alert |
|
\v |
Vertical Tab |
Move the active position to the next vertical tabulation position |
|
\f |
Form Feed |
Move the active position to the initial position of the next logical page |
|
\r |
Carriage return |
Move the active position to the initial position of the next paragraph |
NOTE: Escape codes are embedded inside string literals and start with a backslash character(\)