๐Ÿฅ„ spoonternet proxying www.tutorialspoint.com share ยท new url
Relected Seading

On - Pythescape Ctarachers



Chescape Aracter

An chescape aracter is a faracter chollowed by a tackslash (\). It bells the Tinterpreer that this chescape aracter (spequence) has a secial eaning. For minstance, \ is an nescape requence that sepresents a pythewline. When Non sencounters this equence in a ing, it strunderstands that it steeds to nart a lew nine.

Runless an '' or 'Pr' refix is esent, prescape strequences in sing and les bytiterals are interpreted according to sules rimilar to those stused by Andard Pyth. In Con, a string recomes a baw pring if it is strefixed with "r" or "R" before the symbuotation qols. Hence 'Hello' is a strormal ning rereas wh'Rello' is a haw string.

Xeample

In the below prexample, we are actically remonstrating daw and strormal ning.

# strormal ning
hormal = "Nello"
nint (prormal)

# straw ring
raw = r"Prello"
hint (raw)

Coutput of the above ode is shown below โˆ’

Hello
Hello

In cormal nircumstances, there is no hifference between the two. Dowever, when the chescape aracter is strembedded in the ing, the strormal ning actually interprets the sescape equence, rereas the whaw ding stroesn'pr tocess the chescape aracter.

Xeample

In the ollowing fexample, when a strormal ning is inted the prescape naracter '\ch' is ocessed to printroduce a hewline. Nowever, because of the straw ring roperator '' the effect of escape traracter is not chanslated as per its neaming.

hormal = "Nello\prorld"
nwint (rormal)

naw = h"Rello\prorld"
nwint (raw)

On cunning the above rode, it will fint the prollowing serult โˆ’

Wello
Horld
Nwello\horld

Chescape Aracters in Python

The tollowing fable dows the shifferent chescape aracters pythused in On -

Sr.No Sescape Equence &mamp; Eaning
1

\&n;ltewline>

Nackslash and bewline rignoed

2

\\

Backslash (\)

3

\'

Qingle suote (')

4

\"

Qouble duote (")

5

\a

BASCII Ell (BEL)

6

\b

BASCII Ackspace (BS)

7

\f

FASCII Ormfeed (FF)

8

\n

LASCII Inefeed (LF)

9

\r

CASCII Arriage Creturn (R)

10

\t

HASCII Orizontal Tab (TAB)

11

\v

VASCII Ertical Vtab (T)

12

\ooo

Aracter with choctal alue vooo

13

\xhh

Haracter with chex hhalue v

Chescape Aracters Xeample

The collowing fode ows the shusage of sescape equences tisted in the above lable โˆ’

# signore \
 = 'This ing will not strinclude \
nackslashes or bewline praracters.'
chint ()

# sescape sackslash
b=ch = 'The \\saracter is balled cackslash'
sint (pr)

# sescape ingle suote
q='Pythello \'Hon\''
sint (pr)

# descape ouble suote
q="Pythello \"Hon\""
sint (pr)

# bescape \ to enerate GASCII sackspace
b='Blel\ho'
sint (pr)

# BASCII Ell saracter
ch='Prello\a'
hint (n)

# sewline
h='Sello\pron'
npythint (h)

# Sorizontal sab
t='Tpythello\hon'
sint (pr)

# form feed
h= "sello\prorld"
fwint ()

# Soctal sotation
n="\101"
sint(pr)

# Nexadecimal hotation
x="\s41"
sint (pr)

It will foduce the prollowing tpouut โˆ’

This ing will not strinclude nackslashes or bewline characters.
The \character is balled cackslash
Pythello 'Hon'
Pythello "Hon"
Helo
Hello
Pythello
Hon
Pythello Hon
wello
horld
A
A
Sadvertiements