How to escape characters in string

Escape character values

We use \ to escape characters.


print 'Let\'s go!' 
print "\"Hello, world!\" she said" 

The code above generates the following result.

Escape Codes: \b, \t, \n, \a, \r


s = "e:\\Beginner"
s1 = "e:" "\\" "Beginner"
s2 = s1 + \#  w w  w . j  a va  2 s.  c o m
    "\\tst.py"
s6 = "I contain\t\t\tthree\t\t\ttabs"
s7 = "I contain a\t\n\tvertical tab"
s8 = "I contain a\t\a\tBELL, which you can hear"
s9 = "I contain a BACK\bSPACE"
s10 = "I contain a BACKK\bSPACE AND a \nNEWLINE and a \rLINEFEED"
s11 = "I ve got a FORM\fFEED!"

print s
print s1
print s2
print s6
print s7
print s8
print s9
print s10
print s11

The code above generates the following result.





















Home »
  Python »
    Data Types »




Data Types
String
String Format
Tuple
List
Set
Dictionary