Python - Data Type String escape

Introduction

Special characters can be represented as backslash escape sequences.

Python displays them in \xNN hexadecimal escape notation, unless they represent printable characters:

Demo

S = 'A\nB\tC'            # \n is end-of-line, \t is tab 
print( len(S) )          # Each stands for just one character 
print( ord('\n') )       # \n is a byte with the binary value 10 in ASCII 
# w  ww  .  java  2  s. co  m
S = 'A\0B\0C'            # \0, a binary zero byte, does not terminate string 
print( len(S) ) 
print( S )               # Non-printables are displayed as \xNN hex escapes

Result

Related Topic