Escape Characters and String operators in python:
There is a lot an escape character in python which is denoted by backslash notation.
It is compatible with both single and double quotes.
| Backslash notation | Hexadecimal character | Description |
|---|---|---|
| a | 0x07 | it will perform Bell or alert operation |
| b | 0x08 | it will perform Backspace operation |
| cx | Control-x | |
| C-x | Control-x | |
| e | 0x1b | it will perform Escape operation |
| f | 0x0c | it will perform Form feed operation |
| M-C-x | Meta-Control-x | |
| n | 0x0a | it will perform Newline operation |
| nnn | Octal notation, where n is in the range 0.7 | |
| r | 0x0d | it will return carriage |
| s | 0x20 | Space bar |
| t | 0x09 | Tab |
| v | 0x0b | Vertical tab operation |
| x | Character x | |
| xnn | it will return Hexadecimal notation, where n is in the range 0.9, a.f, or A.F |
Special String Operators in Python:
Let us take an example where
a= ‘Hello’
b= ‘Boy’
| Operator | Description | Example |
| + | It is used for Concatenation of values | a + b will give HelloBoy |
| * | This operator Performs repetition and creates new strings, concatenating multiple copies of the same string according to the digit in multiplication | a*2 will give -HelloHello |
| [] | Slice operator gives the character from the given index value | a[1] will give e |
| [ : ] | Range Slice Operator gives the characters from the given range | a[1:4] will give ell |
| in | Membership Operator will returns true if a character exists in the given string entered | H in a will give 1 |
| not in | Membership Operator will returns true if a character does not exist in the given string entered | Z not in a will give 1 |
| r/R | Raw String functionality | s = r”’ print(s) s = r’ab\’ print(s) |
