Python Escape Characters (PYTHON FUNDAMENTALS)

Created with Sketch.

Python Escape Characters

In String literals, we can use escape characters to associate a special meaning.

>>> s="mohan\nsoftware" 
>>> print(s) 
mohan
software 
>>> s="mohan\tsoftware" 
>>> print(s) 
mohan software 
>>> s="This is " symbol" 
File "<stdin>", line 1 
s="This is " symbol" 
 ^ 
SyntaxError: invalid syntax 
>>> s="This is \" symbol" 
>>> print(s) 
This is " symbol

The following are various important escape characters in Python
1) \n —> New Line
2) \t —> Horizontal Tab
3) \r —> Carriage Return
4) \b —> BackSpace
5) \f —> Form Feed
6) \v —> Vertical Tab
7) \’ —> Single Quote
8) \” —> Double Quote
9) \\ —> Back Slash Symbol
….

 Python Constants:

  •  Constants concept is not applicable in Python.
  •  But it is convention to use only uppercase characters if we don’t want to change value.
  •  MAX_VALUE = 10
  •  It is just convention but we can change the value.

Leave a Reply

Your email address will not be published. Required fields are marked *