Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
12 views

Python Questions and Answers

This document contains a set of multiple choice questions and answers about Python variable names. There are 10 questions that test different aspects of naming variables in Python such as case sensitivity, maximum length, invalid names, and more. The questions provide explanations for the answers.

Uploaded by

wmayo233
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Python Questions and Answers

This document contains a set of multiple choice questions and answers about Python variable names. There are 10 questions that test different aspects of naming variables in Python such as case sensitivity, maximum length, invalid names, and more. The questions provide explanations for the answers.

Uploaded by

wmayo233
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 61

Py

thonQuest
ionsandAnswer
s–Var
iabl
eNames

Thi
ssetofPy
thonMul
ti
pleChoi
ceQuest
ions&Answer
s(MCQs)f
ocuseson“
Var
iabl
eNames”
.

1.I
sPy
thoncasesensi
ti
vewhendeal
i
ngwi
thi
dent
if
ier
s?

a)y
es

b)no

c)machi
nedependent

d)noneoft
hement
ioned

Vi
ewAnswer

Answer
:a

Expl
anat
ion:
Casei
sal
way
ssi
gni
fi
cant
.

2.Whati
sthemaxi
mum possi
blel
engt
hofani
dent
if
ier
?

a)31char
act
ers

b)63char
act
ers

c)79char
act
ers

d)noneoft
hement
ioned

Vi
ewAnswer

Answer
:d

Expl
anat
ion:
Ident
if
ier
scanbeofanyl
engt
h.

3.Whi
choft
hef
oll
owi
ngi
sinv
ali
d?

a)_
a=1

b)_
_a=1

c)_
_st
r__=1

d)noneoft
hement
ioned

Vi
ewAnswer

Answer
:d

Expl
anat
ion:
All
thest
atement
swi
l
lexecut
esuccessf
ull
ybutatt
hecostofr
educedr
eadabi
l
ity
.
4.Whi
choft
hef
oll
owi
ngi
sani
nval
i
dvar
iabl
e?

a)my
_st
ri
ng_
1

b)1st
_st
ri
ng

c)f
oo

d)_

Vi
ewAnswer

Answer
:b

Expl
anat
ion:
Var
iabl
enamesshoul
dnotst
artwi
thanumber
.

5.Whyar
elocal
var
iabl
enamesbegi
nni
ngwi
thanunder
scor
edi
scour
aged?

a)t
heyar
eusedt
oindi
cat
eapr
ivat
evar
iabl
esofacl
ass

b)t
heyconf
uset
hei
nter
pret
er

c)t
heyar
eusedt
oindi
cat
egl
obal
var
iabl
es

d)t
heysl
owdownexecut
ion

Vi
ewAnswer

Answer
:a

Expl
anat
ion:
AsPy thonhasnoconceptofpriv
atev
ari
abl
es,
leadi
ngunder
scor
esar
eusedt
oindi
cat
evar
iabl
est
hat
mustnotbeaccessedfrom out
sidet
heclass.

6.Whi
choft
hef
oll
owi
ngi
snotakey
wor
d?

a)ev
al

b)asser
t

c)nonl
ocal

d)pass

Vi
ewAnswer

Answer
:a

Expl
anat
ion:
eval
canbeusedasav
ari
abl
e.

7.Al
lkey
wor
dsi
nPy
thonar
ein

a)l
owercase
b)UPPERCASE

c)Capi
tal
i
zed

d)Noneoft
hement
ioned

Vi
ewAnswer

Answer
:d

Expl
anat
ion:
True,
Fal
seandNonear
ecapi
tal
i
zedwhi
l
etheot
her
sar
einl
owercase.

8.Whi
choft
hef
oll
owi
ngi
str
uef
orv
ari
abl
enamesi
nPy
thon?

a)unl
i
mit
edl
engt
h

b)al
lpr
ivat
emember
smusthav
eleadi
ngandt
rai
l
ingunder
scor
es

c)under
scor
eandamper
sandar
etheonl
ytwospeci
alchar
act
ersal
l
owed

d)noneoft
hement
ioned

Vi
ewAnswer

Answer
:a

Expl
anat
ion:
Var
iabl
enamescanbeofanyl
engt
h.

9.Whi
choft
hef
oll
owi
ngi
sani
nval
i
dst
atement
?

a)abc=1,
000,
000

b)abc=100020003000

c)a,
b,
c=1000,
2000,
3000

d)a_
b_c=1,
000,
000

Vi
ewAnswer

Answer
:b

Expl
anat
ion:
Spacesar
enotal
l
owedi
nvar
iabl
enames.

10.Whi
choft
hef
oll
owi
ngcannotbeav
ari
abl
e?

a)_
_ini
t__

b)i
n

c)i
t

d)on
Vi
ewAnswer

Answer
:b

Expl
anat
ion:
ini
sakey
wor
d.Thi
ssetofPy
thonMul
ti
pleChoi
ceQuest
ions&Answer
s(MCQs)f
ocuseson“
Basi
c
Oper
ator
s”.

1.Whi
chi
sthecor
rectoper
atorf
orpower
(xy
)?

a)X^
y

b)X*
*y

c)X^
^y

d)Noneoft
hement
ioned

Vi
ewAnswer

Answer
:b

Expl
anat
ion:
Inpy
thon,
poweroper
atori
sx*
*yi
.e.2*
*3=8.

2.Whi
choneoft
hesei
sfl
oordi
vi
sion?

a)/

b)/
/

c)%

d)Noneoft
hement
ioned

Vi
ewAnswer

Answer
:b

Expl
anati
on:
Whenbot hoftheoperandsareintegerthenpythonchopsoutthefract
ionpar
tandgiv
esy outher
ound
offv
alue,
togettheaccur
ateanswerusefloordi v
isi
on.Thisisf
loordi
visi
on.Forex,5/
2=2.5butbothofthe
oper
andsareint
egersoanswerofthisexpressioninpythonis2.Togetthe2.
5answer ,
usefl
oordi
visi
on.

3.Whati
stheor
derofpr
ecedencei
npy
thon?

i
)Par
ent
heses

i
i
)Exponent
ial

i
i
i)Mul
ti
pli
cat
ion

i
v)Di
vi
sion
v
)Addi
ti
on

v
i)Subt
ract
ion

a)i
,
ii
,i
i
i,
iv
,v,
vi

b)i
i
,i
,i
i
i,
iv
,v,
vi

c)i
i
,i
,i
v,
ii
i
,v,
vi

d)i
,
ii
,i
i
i,
iv
,vi
,
v

Vi
ewAnswer

Answer
:a

Expl
anat
ion:
Foror
derofpr
ecedence,
justr
emembert
hisPEMDAS(
simi
l
art
oBODMAS)

4.Whati
stheanswert
othi
sexpr
essi
on,
22%3i
s?

a)7

b)1

c)0

d)5

Vi
ewAnswer

Answer
:b

Expl
anat
ion:
Modul
usoper
atorgi
vest
her
emai
nder
.So,
22%3gi
vest
her
emai
nder
,thati
s,1.

5.Mat
hemat
ical
oper
ati
onscanbeper
for
medonast
ri
ng.St
atewhet
hert
rueorf
alse.

a)Tr
ue

b)Fal
se

Vi
ewAnswer

Answer
:b

Expl
anat
ion:
Youcan’
tper
for
m mat
hemat
ical
oper
ati
ononst
ri
ngev
eni
fthest
ri
ngi
sint
hef
orm:
‘1234…’
.

6.Oper
ator
swi
tht
hesamepr
ecedencear
eev
aluat
edi
nwhi
chmanner
?

a)Lef
ttoRi
ght

b)Ri
ghtt
oLef
t

c)Can’
tsay
d)Noneoft
hement
ioned

Vi
ewAnswer

Answer
:a

Expl
anat
ion:
None.

7.Whati
stheout
putoft
hisexpr
essi
on,
3*1*
*3?

a)27

b)9

c)3

d)1

Vi
ewAnswer

Answer
:c

Explanat
ion:
Fir
stt
hisexpr
essi
onwil
lsol
ve1*
*3becauseexponent
ial
hashi
gherpr
ecedencet
hanmul
ti
pli
cat
ion,
so
1**3=1and3* 1=3.Final
answeri
s3.

8.Whi
choneoft
hef
oll
owi
nghast
hesamepr
ecedencel
evel
?

a)Addi
ti
onandSubt
ract
ion

b)Mul
ti
pli
cat
ion,
Div
isi
onandAddi
ti
on

c)Mul
ti
pli
cat
ion,
Div
isi
on,
Addi
ti
onandSubt
ract
ion

d)Addi
ti
onandMul
ti
pli
cat
ion

Vi
ewAnswer

Answer
:a

Explanat
ion:
“Additi
onandSubtr
acti
on”areatt
hesamepr ecedencel
evel.Si
mil
arl
y,“
Mult
ipl
i
cati
onandDivi
sion”ar
e
atthesamepr ecedencel
evel
.However,
Multi
pli
cat
ionandDivisi
onoperator
sar
eatahigherpr
ecedencel
evelthan
Additi
onandSubt r
acti
onoperat
ors.

9.Theexpr
essi
onI
nt(
x)i
mpl
i
est
hatt
hev
ari
abl
exi
sconv
ert
edt
oint
eger
.St
atewhet
hert
rueorf
alse.

a)Tr
ue

b)Fal
se

Thi
ssetofPy
thonMul
ti
pleChoi
ceQuest
ions&Answer
s(MCQs)f
ocuseson“
Cor
eDat
aTy
pes”
.
1.Whi
choft
hesei
nnotacor
edat
aty
pe?

a)Li
sts

b)Di
cti
onar
y

c)Tupl
es

d)Cl
ass

Vi
ewAnswer

Answer
:d

Expl
anat
ion:
Classi
sauserdef
ineddat
aty
pe.

2.Gi
venaf
unct
iont
hatdoesnotr
etur
nanyv
alue,
Whatv
aluei
sthr
ownbydef
aul
twhenexecut
edi
nshel
l
.

a)i
nt

b)bool

c)v
oid

d)None

Vi
ewAnswer

Answer
:d

Expl
anat
ion:
Pyt
honshel
lthr
owsaNoneTy
peobj
ectback.

3.Fol
l
owi
ngsetofcommandsar
eexecut
edi
nshel
l
,whatwi
l
lbet
heout
put
?

>>>st
r="
hel
l
o"

>>>st
r[
:2]

>>>

a)he

b)l
o

c)ol
l
eh

d)hel
l
o

Vi
ewAnswer

Answer
:a
Expl
anat
ion:
Wear
epr
int
ingonl
ythe1stt
woby
tesofst
ri
ngandhencet
heansweri
s“he”
.

4.Whi
choft
hef
oll
owi
ngwi
l
lrunwi
thouter
ror
s?

a)r
ound(
45.
8)

b)r
ound(
6352.
898,
2,
5)

c)r
ound(
)

d)r
ound(
7463.
123,
2,
1)

Vi
ewAnswer

Answer
:a

Expl
anat
ion:
Execut
ehel
p(r
ound)i
ntheshel
ltogetdet
ail
soft
hepar
amet
erst
hatar
epassedi
ntot
her
oundf
unct
ion.

5.Whati
sther
etur
nty
peoff
unct
ioni
d?

a)i
nt

b)f
loat

c)bool

d)di
ct

Vi
ewAnswer

Answer
:a

Expl
anat
ion:
Execut
ehel
p(i
d)t
ofi
ndoutdet
ail
sinpy
thonshel
l
.i
dret
urnsai
ntegerv
aluet
hati
suni
que.

6.I
npythonwedonotspeci
fyt
ypes,
i
tisdi
rect
lyi
nter
pret
edbyt
hecompi
l
er,
soconsi
dert
hef
oll
owi
ngoper
ati
ont
obe
per
for
med.

>>>x=13?2

obj
ect
ivei
stomakesur
exhasai
ntegerv
alue,
sel
ectal
lthatappl
y(py
thon3.
xx)

a)x=13/
/2

b)x=i
nt(
13/2)

c)x=13%2

d)Al
loft
hement
ioned

Vi
ewAnswer
Answer
:d

Expl
anat
ion:
//i
sint
egeroper
ati
oni
npy
thon3.
0andi
nt(
..
)isat
ypecastoper
ator
.

7.Whater
roroccur
swheny
ouexecut
e?

appl
e=mango

a)Sy
ntaxEr
ror

b)NameEr
ror

c)Val
ueEr
ror

d)Ty
peEr
ror

Vi
ewAnswer

Answer
:b

Expl
anat
ion:
Mangoi
snotdef
inedhencenameer
ror
.

8.Car
eful
l
yobser
vet
hecodeandgi
vet
heanswer
.

defexampl
e(a)
:

a=a+'
2'

a=a*
2

r
etur
na

>>>exampl
e("
hel
l
o")

a)i
ndent
ati
onEr
ror

b)cannotper
for
m mat
hemat
ical
oper
ati
ononst
ri
ngs

c)hel
l
o2

d)hel
l
o2hel
l
o2

Vi
ewAnswer

Answer
:a

Expl
anat
ion:
Pyt
honcodeshav
etobei
ndent
edpr
oper
ly.

9.Whatdat
aty
pei
stheobj
ectbel
ow?

L=[
1,23,
‘hel
l
o’,
1].

a)l
i
st
b)di
cti
onar
y

c)ar
ray

d)t
upl
e

Vi
ewAnswer

Answer
:a

Expl
anat
ion:
Listdat
aty
pecanst
oreanyv
alueswi
thi
nit
.

10.I
nor
dert
ost
orev
aluesi
nter
msofkeyandv
alueweusewhatcor
edat
aty
pe.

a)l
i
st

b)t
upl
e

c)cl
ass

d)di
cti
onar
y

Vi
ewAnswer

Answer
:d

Expl
anat
ion:
Dict
ionar
yst
oresv
aluesi
nter
msofkey
sandv
alues.

11.Whi
choft
hef
oll
owi
ngr
esul
tsi
naSy
ntaxEr
ror?

a)‘
”Onceuponat
ime…”
,shesai
d.’

b)“
Hesai
d,‘
Yes!
'

c)‘
3\’

d)”
’That
’sokay
”’

Vi
ewAnswer

adv
ert
isement

12.Thef
oll
owi
ngi
sdi
spl
ayedbyapr
intf
unct
ioncal
l
:

t
om

di
ck

har
ry

Sel
ectal
loft
hef
unct
ioncal
l
sthatr
esul
tint
hisout
put
a)pr
int
(”’
tom

\
ndi
ck

\
nhar
ry”
’)

b)pr
int
(”’
tomdi
ckhar
ry”
’)

c)pr
int
(‘
tom\
ndi
ck\
nhar
ry’
)

d)pr
int
(‘
tom

di
ck

har
ry’
)

Vi
ewAnswer

Answer
:c

Expl
anat
ion:
The\
naddsanewl
i
ne.

13.Whati
stheav
eragev
alueoft
hecodet
hati
sexecut
edbel
ow?

>>>gr
ade1=80

>>>gr
ade2=90

>>>av
erage=(
grade1+gr
ade2)/2

a)85.
0

b)85.
1

c)95.
0

d)95.
1

Vi
ewAnswer

Answer
:a

Expl
anat
ion:
Causeadeci
mal
val
ueof0t
oappearasout
put
.

14.Sel
ectal
lopt
ionst
hatpr
int

hel
l
o-how-
are-
you

a)pr
int
(‘
hel
l
o’,
‘how’
,‘
are’
,‘
you’
)

b)pr
int
(‘
hel
l
o’,
‘how’
,‘
are’
,‘
you’
+‘-
‘*4)

c)pr
int
(‘
hel
l
o-‘
+‘how-
are-
you’
)
d)pr
int
(‘
hel
l
o’+‘
-
‘+‘
how’
+‘-
‘+‘
are’
+‘y
ou’
)

Vi
ewAnswer

Answer
:c

Expl
anat
ion:
Execut
eint
heshel
l
.

15.Whati
sther
etur
nval
ueoft
runc(
)?

a)i
nt

b)bool

c)f
loat

d)None

Vi
ewAnswer

Answer
:a

Expl
anat
ion:
Execut
ehel
p(mat
h.t
runc)t
ogetdet
ail
s

Vi
ewAnswer

Answer
:a

Expl
anat
ion:
None.

10.Whi
choneoft
hef
oll
owi
nghast
hehi
ghestpr
ecedencei
ntheexpr
essi
on?

a)Exponent
ial

b)Addi
ti
on

c)Mul
ti
pli
cat
ion

d)Par
ent
heses

Vi
ewAnswer

Answer
:d

Expl
anat
ion:Justr
emember :PEMDAS,thatis,Par
enthesi
s,Exponent
iat
ion,
Divi
sion,
Mult
ipl
i
cation,Addi
ti
on,
Subt
ract
ion.Notet
hattheprecedenceorderofDiv
isi
onandMul ti
pli
cati
onisthesame.Li
kewise,t
heorderofAddi
ti
on
andSubtr
acti
onisalsothesame.

Thi
ssetofPy
thonMul
ti
pleChoi
ceQuest
ions&Answer
s(MCQs)f
ocuseson“
Numer
icTy
pes”
.
1.Whati
stheout
putofpr
int0.
1+0.
2==0.
3?

a)Tr
ue

b)Fal
se

c)Machi
nedependent

d)Er
ror

Vi
ewAnswer

Answer
:b

Explanat
ion:
Neit
herof0.1,
0.2and0.3canber epresentedaccur
atel
yinbi
nary
.Ther
oundof
fer
ror
sfr
om 0.
1and0.
2
accumulateandhencether
eisadif
ferenceof5.5511e-17between(0.1+0.
2)and0.
3.

2.Whi
choft
hef
oll
owi
ngi
snotacompl
exnumber
?

a)k=2+3j

b)k=compl
ex(
2,3)

c)k=2+3l

d)k=2+3J

Vi
ewAnswer

Answer
:c

Expl
anat
ion:
l(orL)st
andsf
orl
ong.

3.Whati
sthet
ypeofi
nf?

a)Bool
ean

b)I
nteger

c)Fl
oat

d)Compl
ex

Vi
ewAnswer

Answer
:c

Expl
anat
ion:
Inf
ini
tyi
saspeci
alcaseoff
loat
ingpoi
ntnumber
s.I
tcanbeobt
ainedbyf
loat
(‘
inf
’)
.

4.Whatdoes~4ev
aluat
eto?

a)-
5
b)-
4

c)-
3

d)+3

Vi
ewAnswer

Answer
:a

Expl
anat
ion:
~xi
sequi
val
entt
o-(
x+1)
.

5.Whatdoes~~~~~~5ev
aluat
eto?

a)+5

b)-
11

c)+11

d)-
5

Vi
ewAnswer

Answer
:a

Expl
anat
ion:
~xi
sequi
val
entt
o-(
x+1)
.

6.Whi
choft
hef
oll
owi
ngi
sincor
rect
?

a)x=0b101

b)x=0x4f
5

c)x=19023

d)x=03964

Vi
ewAnswer

Answer
:d

Expl
anat
ion:
Number
sst
art
ingwi
tha0ar
eoct
alnumber
sbut9i
sn’
tal
l
owedi
noct
alnumber
s.

7.Whati
sther
esul
tofcmp(
3,1)
?

a)1

b)0

c)Tr
ue

d)Fal
se
Vi
ewAnswer

Answer
:a

Expl
anat
ion:
cmp(
x,y
)ret
urns1i
fx>y
,0i
fx==yand-
1ifx<y
.

8.Whi
choft
hef
oll
owi
ngi
sincor
rect
?

a)f
loat
(‘
inf
’)

b)f
loat
(‘
nan’
)

c)f
loat
(’
56’
+’
78’
)

d)f
loat
(’
12+34′
)

Vi
ewAnswer

Answer
:d

Expl
anat
ion:
‘+’
cannotbeconv
ert
edt
oaf
loat
.

9.Whati
sther
esul
tofr
ound(
0.5)–r
ound(
-0.
5)?

a)1.
0

b)2.
0

c)0.
0

d)Noneoft
hement
ioned

Vi
ewAnswer

Answer
:b

Explanat
ion:Py
thonroundsoffnumber
sawayf
rom 0whent
henumbert
ober
oundedof
fisexact
lyhal
fwayt
hrough.
round(0.
5)is1andround(-
0.5)i
s-1.

10.Whatdoes3^4ev
aluat
eto?

a)81

b)12

c)0.
75

d)7

Vi
ewAnswer
Answer
:d

Expl
anat
ion:
^ist
heBi
nar
yXORoper
ator
.Py
thonQuest
ionsandAnswer
s–Pr
ecedenceandAssoci
ati
vi
ty–1

Thi
ssetofPy
thonMul
ti
pleChoi
ceQuest
ions&Answer
s(MCQs)f
ocuseson“
PrecedenceandAssoci
ati
vi
ty–1”
.

1.Thev
alueoft
heexpr
essi
ons4/
(3*
(2-
1))and4/
3*(
2-1)i
sthesame.St
atewhet
hert
rueorf
alse.

a)Tr
ue

b)Fal
se

Vi
ewAnswer

Answer
:a

Expl
anat
ion:
Alt
hought hepr
esenceofparent
hesisdoesaff
ectt
heorderofprecedence,
inthecaseshownabov
e,i
tis
notmaki
ngadiff
erence.Theresul
tofbot
hoft heseexpr
essi
onsis1.
333333333.Hencet hest
atementi
str
ue.

2.Thev
alueoft
heexpr
essi
on:

4+3%5

a)4

b)7

c)2

d)0

Vi
ewAnswer

Answer
:b

Expl
anati
on:Theorderofpr
ecedencei
s:%,
+.Hencet
heexpr
essi
onabov
e,onsi
mpl
i
ficat
ionr
esul
tsi
n4+3=7.
Hencetheresul
tis7.

3.Ev
aluat
etheexpr
essi
ongi
venbel
owi
fA=16andB=15.

A%B/
/A

a)0.
0

b)0

c)1.
0

d)1
Vi
ewAnswer

Answer
:b

Expl
anat
ion:
Theabov
eexpr
essi
oni
sev
aluat
edas:
16%15/
/16,
whi
chi
sequal
to1/
/16,
whi
chr
esul
tsi
n0.

4.Whi
choft
hef
oll
owi
ngoper
ator
shasi
tsassoci
ati
vi
tyf
rom r
ightt
olef
t?

a)+

b)/
/

c)%

d)*
*

Vi
ewAnswer

Answer
:d

Explanat
ion:Al
loftheoperator
sshownabovehav
eassoci
ati
vi
tyf
rom l
eftt
ori
ght
,exceptexponent
iat
ionoper
ator(
**)
whichhasi t
sassociat
ivi
tyfr
om ri
ghtt
olef
t.

5.Whati
sthev
alueofxi
f:

x=i
nt(
43.
55+2/
2)

a)43

b)44

c)22

d)23

Vi
ewAnswer

Answer
:b

Explanati
on:Theexpr
essionshownaboveisanexampl
eofexpl
i
citconv
ersi
on.I
tisev
aluat
edasi
nt(
43.
55+1)=
i
nt(44.55)=44.Hencetheresul
toft
hisexpressi
oni
s44.

6.Whati
sthev
alueoft
hef
oll
owi
ngexpr
essi
on?

2+4.
00,
2**
4.0

a)(
6.0,
16.
0)

b)(
6.00,
16.
00)
c)(
6,16)

d)(
6.00,
16.
0)

Vi
ewAnswer

Answer
:a

Explanat
ion:
Theresul
toft
heexpressi
onshownabov
eis(
6.0,
16.
0).Thi
sisbecauset
her
esul
tisaut
omat
ical
l
y
roundedofftoonedeci
malpl
ace.

7.Whi
choft
hef
oll
owi
ngi
sthet
runcat
iondi
vi
sionoper
ator
?

a)/

b)%

c)/
/

d)|

Vi
ewAnswer

Answer
:c

Expl
anat
ion:/
/istheoperat
orf
ortr
uncati
ondiv
ision.I
titcal
l
edsobecausei
tret
urnsonl
ythei
ntegerpar
toft
he
quot
ient
,tr
uncat
ingthedeci
malpar
t.Forexample:20/
/3=6.

8.Whatar
ethev
aluesoft
hef
oll
owi
ngexpr
essi
ons:

2*
*(3*
*2)

(
2**
3)*
*2

2*
*3*
*2

a)64,
512,
64

b)64,
64,
64

c)512,
512,
512

d)512,
64,
512

Vi
ewAnswer

Answer
:d

Expl
anati
on:
Expr
essi
on1i seval
uat
edas:
2**
9,whi
chisequalto512.
Expressi
on2isevaluat
edas8**2,whi
chis
equalt
o64.Thel
astexpr
essioni
seval
uat
edas2**
(3*
*2).Thi
sisbecausetheassoci
ati
vi
tyof**oper
atori
sfrom
r
ightt
olef
t.Hencet
her
esul
toft
het
hir
dexpr
essi
oni
s512.

adv
ert
isement

9.Whati
sthev
alueoft
hef
oll
owi
ngexpr
essi
on:

8/
4/2,
8/(
4/2)

a)(
1.0,
4.0)

b)(
1.0,
1.0)

c)(
4.0.1.
0)

d)(
4.0,
4.0)

Vi
ewAnswer

Answer
:a

Expl
anat
ion:
Theabov
eexpr
essi
onsar
eev
aluat
edas:
2/2,
8/2,
whi
chi
sequal
to(
1.0,
4.0)
.

10.Whati
sthev
alueoft
hef
oll
owi
ngexpr
essi
on:

f
loat
(22/
/3+3/
3)

a)8

b)8.
0

c)8.
3

d)8.
33

Vi
ewAnswer

Answer
:b

Expl
anat
ion:
Theexpressi
onshownaboveisev
aluat
edas: f
loat
(7+1)=fl
oat(
8)=8.
0.Hencet
her
esul
toft
his
expr
essi
onis8.
0PythonQuest
ionsandAnswer
s–Pr ecedenceandAssoci
ati
vit
y–2

Thi
ssetofPy
thonMul
ti
pleChoi
ceQuest
ions&Answer
s(MCQs)f
ocuseson“
PrecedenceandAssoci
ati
vi
ty–2”
.

1.Whati
stheout
putoft
hef
oll
owi
ngexpr
essi
on:

pr
int
(4.
00/
(2.
0+2.
0))
a)Er
ror

b)1.
0

c)1.
00

d)1

Vi
ewAnswer

Answer
:b

Expl
anat
ion:
Ther
esul
toft
heexpr
essi
onshownabov
eis1.
0becausepr
intr
oundsof
fdi
git
s.

2.Consi
dert
heexpr
essi
ongi
venbel
ow.Thev
alueofXi
s:

X=2+9*
((3*
12)
-8)
/10

a)30.
0

b)30.
8

c)28.
4

d)27.
2

Vi
ewAnswer

Answer
:d

Expl
anati
on:
Theexpr
essi
onshownaboveiseval
uatedas:2+9*(
36-
8)/
10,
whi
chsi
mpl
i
fiest
ogi
ve2+9*
(2.
8),
whi
chi
s
equalt
o2+25.2=27.
2.Hencet
her
esultoft
hisexpr
essionis27.
2.

3.Whi
choft
hef
oll
owi
ngexpr
essi
onsi
nvol
vescoer
cionwhenev
aluat
edi
nPy
thon?

a)4.
7–1.
5

b)7.
9*6.
3

c)1.
7%2

d)3.
4+4.
6

Vi
ewAnswer

Answer
:c

Explanat
ion:
Coer
cionist
hei
mpl i
cit(aut
omatic)conversi
onofoperandst
oacommontype.Coer
cioni
s
automati
call
yper
formedonmixed-ty
peexpressions.Theexpr
ession1.7%2i
seval
uat
edas1.7%2. 0(
thati
s,
automati
cconver
sionofi
ntt
of l
oat).
4.Whati
sthev
alueoft
hef
oll
owi
ngexpr
essi
on:

24/
/6%3,
24/
/4/
/2

a)(
1,3)

b)(
0,3)

c)(
1,0)

d)(
3,1)

Vi
ewAnswer

Answer
:a

Expl
anati
on:Theexpressi
onsar
eevaluat
edas:4%3and6//2respect
ively
.Thisr
esul
tsi
ntheanswer(
1,3)
.Thi
sis
becausetheassoci
ati
vit
yofbot
hoftheexpr
essionsshownaboveisleftt
oright
.

5.Whi
chamongt
hef
oll
owi
ngl
i
stofoper
ator
shast
hehi
ghestpr
ecedence?

+,
-,*
*,%,
/,<<,
>>,
|

a)<<,
>>

b)*
*

c)|

d)%

Vi
ewAnswer

Answer
:b

Expl
anat
ion:
Thehi
ghestpr
ecedencei
sthatoft
heexponent
iat
ionoper
ator
,thati
sof*
*.

adv
ert
isement

6.Whati
sthev
alueoft
heexpr
essi
on:

f
loat
(4+i
nt(
2.39)
%2)

a)5.
0

b)5

c)4.
0
d)4

Vi
ewAnswer

Answer
:c

Expl
anati
on:Theaboveexpr
essi
onisanexampl
eofexpli
citconver
sion.I
tisev
aluat
edas:
float
(4+i
nt(
2.39)
%2)=
fl
oat
(4+2%2)=float
(4+0)=4.
0.Hencet
heresul
toft
hisexpressi
onis4.0.

7.Whi
choft
hef
oll
owi
ngexpr
essi
onsi
sanexampl
eoft
ypeconv
ersi
on?

a)4.
0+f
loat
(3)

b)5.
3+6.
3

c)5.
0+3

d)3+7

Vi
ewAnswer

Answer
:a

Expl
anati
on:Typeconver
sionisnot
hingbutexpl
i
citconv
ersi
onofoper
andst oaspeci
fi
cty
pe.Options‘
b’ and‘
c’ar
e
examplesofi
mplici
tconversi
onwhereasopti
on‘a’
isanexampl
eofexpli
citconv
ersi
onortypeconver
sion.

8.Whi
choft
hef
oll
owi
ngexpr
essi
onsr
esul
tsi
naner
ror
?

a)f
loat
(‘
10’
)

b)i
nt(
‘10’
)

c)f
loat
(’
10.
8’)

d)i
nt(
’10.
8’)

Vi
ewAnswer

Answer
:d

Expl
anat
ion:
All
oft
heabov
eexampl
esshowexpl
i
citconv
ersi
on.Howev
ert
heexpr
essi
oni
nt(
’10.
8’)r
esul
tsi
naner
ror
.

9.Whati
sthev
alueoft
heexpr
essi
on:

4+2*
*5/
/10

a)3

b)7

c)77
d)0

Vi
ewAnswer

Answer
:b

Expl
anat
ion:
Theor
derofprecedencei
s:*
*, /
/,+.Theexpr
essi
on4+2*
*5/
/10i
sev
aluat
edas4+32/
/10,
whi
chi
sequal
to4+3=7.Hencet
heresul
toftheexpr
essionshownabov ei
s7.

10.Theexpr
essi
on2*
*2*
*3i
sev
aluat
esas:
(2*
*2)
**3.St
atewhet
hert
hisst
atementi
str
ueorf
alse.

a)Tr
ue

b)Fal
se

Vi
ewAnswer

Answer
:b

Expl
anat i
on:Theval
ueoftheexpressi
on(2**2)*
*3=4**3=64.Whent heexpr essi
on2**2**3isev
aluat
edinpython,
wegett heresul
tas256,becausethi
sexpressi
oniseval
uatedas2**
(2**3).Thisisbecausetheassoci
ati
vi
tyof
exponentiat
ionoper
ator(
**)i
sf r
om ri
ghtt
ol ef
tandnotfr
om lef
ttor
ight.PythonQuestionsandAnswers–Bi t
wise–
1

Thi
ssetofPy
thonMul
ti
pleChoi
ceQuest
ions&Answer
s(MCQs)f
ocuseson“
Bit
wise–1”
.

1.Whati
sther
esul
toft
hesni
ppetofcodeshownbel
owi
fx=1?

x<<2

a)8

b)1

c)2

d)4

Vi
ewAnswer

Answer
:d

Expl
anation:Thebinaryf
orm of1i
s0001.Theexpressi
onx<<2i
mpli
eswear
eper
for
mingbi
twi
sel
eftshi
ftonx.Thi
s
shi
ftyi
eldsthevalue:0100,
whichi
sthebinar
yform oft
henumber4.

2.Theout
putoft
heexpr
essi
oni
s:
bi
n(29)

a)‘
0b10111’

b)‘
0b11101’

c)‘
0b11111’

d)‘
0b11011’

Vi
ewAnswer

Answer
:b

Expl
anat
ion:
Thebi
nar
yfor
m oft
henumber29i
s11101.Hencet
heout
putoft
hisexpr
essi
oni
s‘0b11101’
.

3.Whati
sthev
alueofxi
f:

x>>2=2

a)8

b)4

c)2

d)1

Vi
ewAnswer

Answer
:a

Expl
anati
on:
Whenthevalueofxisequal
to8(
1000)
,thenx>>2(
bit
wiser
ightshi
ft
)yi
eldst
hev
alue0010,
whi
chi
s
equalt
o2.Hencet
hevalueofxis8.

4.Whati
sther
esul
toft
heexpr
essi
on:

i
nt(
1011)
?

a)1011

b)11

c)13

c)1101

Vi
ewAnswer
Answer
:a

Expl
anat
ion:
Theresul
toftheexpressi
onshownwi
llbe1011.Thi
sisbecausewehav
enotspeci
fi
edt
hebasei
nthi
s
expr
essi
on.Hencei
tautomati
call
ytakest
hebaseas10.

5.Tof
indt
hedeci
mal
val
ueof1111,
thati
s15,
wecanuset
hef
unct
ion:

a)i
nt(
1111,
10)

b)i
nt(
‘1111’
,
10)

c)i
nt(
1111,
2)

d)i
nt(
‘1111’
,
2)

Vi
ewAnswer

Answer
:d

Expl
anat
ion:
Theexpr
essi
oni
nt(
‘1111’
,
2)gi
vest
her
esul
t15.Theexpr
essi
oni
nt(
‘1111’
,10)wi
l
lgi
vet
her
esul
t1111.

6.Whati
sther
esul
toft
heexpr
essi
oni
fx=15andy
=12:

x&y

a)b1101

b)0b1101

c)12

d)1101

Vi
ewAnswer

Answer
:c

Expl
anati
on: Thesymbol‘
&’r
epresent
sbi
twi
seAND.Thisgi
ves1ifbot
hthebit
sareequal
to1, el
sei
tgives0.The
bi
naryform of15is1111andthatof12i
s1100.Henceonper
for
mingthebi
twiseANDoperat
ion,weget1100,whi
ch
i
sequal t
o12.

7.Whi
choft
hef
oll
owi
ngexpr
essi
onsr
esul
tsi
naner
ror
?

a)i
nt(
1011)

b)i
nt(
‘1011’
,
23)

c)i
nt(
1011,
2)

d)i
nt(
‘1011’
)

Vi
ewAnswer
Answer
:c

Expl
anat
ion:
Theexpr
essi
oni
nt(
1011,
2)r
esul
tsi
naner
ror
.Hadwewr
it
tent
hisexpr
essi
onasi
nt(
‘1011’
,
2),
thent
her
e
woul
dnotbeanerror
.

adv
ert
isement

8.Whi
choft
hef
oll
owi
ngr
epr
esent
sthebi
twi
seXORoper
ator
?

a)&

b)^

c)|

d)!

Vi
ewAnswer

Answer
:b

Expl
anat
ion:
The^oper
atorr
epr
esentbi
twi
seXORoper
ati
on.&:
bit
wiseAND,
|:bi
twi
seORand!r
epr
esent
sbi
twi
se
NOT.

9.Whati
sthev
alueoft
hisexpr
essi
on?

bi
n(0x8)

a)‘
0bx1000’

b)8

c)1000

d)‘
0b1000’

Vi
ewAnswer

Answer
:d

Expl
anati
on:Thepref
ix0xspecif
iest
hattheval
uei
shexadeci
mal
innat
ure.Whenweconv
ertt
hishexadeci
mal
val
ue
tobi
naryfor
m, wegetther
esultas:‘
0b1000’
.

10.Whati
sther
esul
toft
heexpr
essi
on:

0x
35|
0x75

a)115
b)116

c)117

d)118

Vi
ewAnswer

Answer
:c

Explanati
on:Thebinar
yv al
ueof0x35i
s110101andthatof0x75is1110101.OnOR-i
ngtheset
wovalueswegetthe
outputas:1110101,whichisequal
to117.Hencet
heresul
toftheaboveexpressi
oni
s117.Pyt
honQuesti
onsand
Answer s–Bitwi
se–2

Thi
ssetofPy
thonMul
ti
pleChoi
ceQuest
ions&Answer
s(MCQs)f
ocuseson“
Bit
wise–2”
.

1.Itisnotpossi
blef
orthet
wo’
scompl
ementv
aluet
obeequal
tot
heor
igi
nal
val
uei
nanycase.St
atewhet
hert
his
statementistr
ueorfal
se.

a)Tr
ue

b)Fal
se

Vi
ewAnswer

Answer
:b

Explanat
ion:Inmostcasest
hev al
ueoftwo’scomplementi
sdi f
fer
entfr
om theorigi
nalv
alue.Howev
er,t
her
eare
casesinwhi chthetwo’
scomplementval
uemaybeequal totheorigi
nalval
ue.Forexample,t
hetwo’
scomplementof
10000000i salsoequal
to10000000.Hencethest
atementisfal
se.

2.Theone’
scompl
ementof110010101i
s:

a)001101010

b)110010101

c)001101011

d)110010100

Vi
ewAnswer

Answer
:a

Expl
anati
on:Theone’
scomplementofavaluei
sobtainedbysi
mpl
ychangi
ngal
lthe1’
sto0’
sandal
lthe0’
sto1’
s.
Hencetheone’scompl
ementof110010101is001101010.

3.Bi
twi
se_
___
___
__gi
ves1i
fei
theroft
hebi
tsi
s1and0whenbot
hoft
hebi
tsar
e1.
a)OR

b)AND

c)XOR

d)NOT

Vi
ewAnswer

Answer
:c

Expl
anat
ion:
Bit
wiseXORgi
ves1i
fei
theroft
hebi
tsi
s1and0whenbot
hoft
hebi
tsar
e1.

4.Ther
esul
toft
heexpr
essi
onshownbel
owi
s:

4^
12

a)2

b)4

c)8

d)12

Vi
ewAnswer

Answer
:c

Explanat
ion:
^istheXORoper
ator
.Thebi
nar
yfor
m of4i
s0100andt
hatof12i
s1100.Ther
efor
e,0100^
1100i
s1000,
whichisequalt
o8.

5.Anyoddnumberonbei
ngAND-
edwi
th_
___
___
_al
way
sgi
ves1.Hi
nt:
Anyev
ennumberonbei
ngAND-
edwi
tht
his
val
uealway
sgiv
es0.

a)10

b)2

c)1

d)0

Vi
ewAnswer

Answer
:c

Expl
anati
on:Anyoddnumberonbei
ngAND-
edwi
th1al
way
sgi
ves1.Anyev
ennumberonbei
ngAND-
edwi
tht
his
val
uealwaysgiv
es0.
6.Whati
sthev
alueoft
hisexpr
essi
on:

bi
n(10-
2)+bi
n(12^
4)

a)0b10000

b)0b10001000

c)0b1000b1000

d)0b10000b1000

Vi
ewAnswer

Answer
:d

Expl
anat
ion:Theoutputofbi
n(10-
2)=0b1000andt
hatofbi
n(12^
4)i
sob1000.Hencet
heout
putoft
heabov
e
expr
essi
onis:0b10000b1000.

7.Whi
choft
hef
oll
owi
ngexpr
essi
onscanbeusedt
omul
ti
plyagi
vennumber‘
a’by4?

a)a<<2

b)a<<4

c)a>>2

d)a>>4

Vi
ewAnswer

Answer
:a

Explanat
ion:
Letusconsideranexamplewher
eina=2.Thebi
naryfor
m of2is0010.Whenwel
eftshi
ftt
hisv
alueby2,
weget1000, thev
alueofwhichis16.Hencei
fwewantt omult
ipl
yagivennumber‘a’
by4,
wecanusetheexpressi
on:
a<<2.

8.Whati
stheout
putoft
hecodeshowbel
owi
fa=10andb=20?

adv
ert
isement

a=10

b=20

a=a^
b

b=a^
b

a=a^
b
pr
int
(a,
b)

a)1020

b)1010

c)2010

d)2020

Vi
ewAnswer

Answer
:c

Expl
anat
ion:
Thecodeshownaboveisusedt
oswapthecont
entsoft
womemor
ylocat
ionsusi
ngbi
twi
seX0R
oper
ator
.Hencet
heoutputoft
hecodeshownabov
eis:2010.

9.Whati
sthet
wo’
scompl
ementof-
44?

a)1011011

b)11010100

c)11101011

d)10110011

Vi
ewAnswer

Answer
:b

Expl
anat
ion:Thebinar
yform of-
44i
s00101100.Theone’
scompl
ementoft
hisv
aluei
s11010011.Onaddi
ngonet
o
thi
sweget:11010100(two’
scomplement
).

10.Whati
sthev
alueoft
heexpr
essi
on:

~100?

a)101

b)-
101

c)100

d)-
100

Vi
ewAnswer

Answer
:b

Expl
anat
ion:
Supposewehav
eanexpr
essi
on~A.Thi
sisev
aluat
edas:
-A–1.Ther
efor
e,t
heexpr
essi
on~100i
s
ev
aluat
edas-
100–1,
whi
chi
sequal
to-
101.Py
thonQuest
ionsandAnswer
s–Bool
ean

Thi
ssetofPy
thonMul
ti
pleChoi
ceQuest
ions&Answer
s(MCQs)f
ocuseson“
Bool
ean”
.

1.Theout
putoft
hesni
ppetofcodeshownbel
ow?

bool
(‘
Fal
se’
)

bool
()

a)Tr
ue

Tr
ue

b)Fal
se

Tr
ue

c)Fal
se

Fal
se

d)Tr
ue

Fal
se

Vi
ewAnswer

Answer
:d

Explanati
on:TheBooleanf
unct
ionret
urnst
ruei
ftheargumentpassedtot heboolf
uncti
ondoesnotamountt
ozero.
I
nt hefir
stexample,
thestr
ing‘
Fal
se’i
spassedt
ot hefunct
ionbool.Thi
sdoesnotamountt ozer
oandhencethe
outputistr
ue.Int
hesecondfunct
ion,
anemptyli
stispassedtothefuncti
onbool.Hencetheout
puti
sfal
se.

2.Whati
stheout
putoft
hesni
ppetofcodeshownbel
ow?

[
'
hel
l
o',
'mor
ning'
]
[bool
('
'
)]

a)er
ror

b)noout
put

c)hel
l
o

d)mor
ning

Vi
ewAnswer

Answer
:c
Expl
anat
ion:Theli
neofcodeshownabovecanbesimpl
if
iedtostat
ethat‘hell
o’shoul
dbepr
int
edi
fthear
gument
passedt
ot heBool
eanfunct
ionamount
stozero,
else‘
morning’
will
beprinted.

3.Whati
stheout
putoft
hecodeshownbel
ow?

not
(3>4)

not
(1&1)

a)Tr
ue

Tr
ue

b)Tr
ue

Fal
se

c)Fal
se

Tr
ue

d)Fal
se

Fal
se

Vi
ewAnswer

Answer
:b

Expl
anati
on:
Thefuncti
onnotret
urnst
ruei
fthear
gumentamountst
ofal
se,
andfalsei
fthear
gumentamount
sto
tr
ue.Hencet
hefi
rstfunct
ionr
etur
nsfal
se,
andthesecondf
unct
ionr
etur
nsfal
se.

4.Whati
stheout
putoft
hecodeshown?

[
'
f'
,'
t'
]
[bool
('
spam'
)]

a)t

b)f

c)Noout
put

d)Er
ror

Vi
ewAnswer

Answer
:a

Explanat
ion:
Thel
ineofcodecanbetranslat
edtostat
ethat‘
f’i
spr
int
edi
ftheargumentpassedtotheBoolean
functi
onamountt
ozero.Else‘
t’
ispr
inted.Theargumentgi
ventot
heBool
eanfuncti
onintheabovecaseis‘spam’
,
whi
chdoesnotamountt
ozer
o.Hencet
heout
puti
s:t
.

5.Whati
stheout
putoft
hecodeshownbel
ow?

l
=[1,
0,2,
0,'
hel
l
o',
''
,[
]]

l
i
st(
fi
lt
er(
bool
,l
))

a)Er
ror

b)[
1,0,
2,0,
‘hel
l
o’,
”,[
]]

c)[
1,0,
2,‘
hel
l
o’,
”,[
]]

d)[
1,2,
‘hel
l
o’]

Vi
ewAnswer

Answer
:d

Expl
anat
ion:Thecodeshownabov
eret
urnsanewli
stcont
aini
ngonl
ythoseel
ement
soft
hel
i
stl
whi
chdonot
amounttozero.Hencet
heout
puti
s:[
1,2,‘
hel
l
o’]

6.Whati
stheout
putoft
hef
oll
owi
ngcodei
fthesy
stem dat
eis21stJune,
2017(
Wednesday
)?

[]or{
}

{
}or[]

a)[]

{
}

b)[]

[]

c){
}

[]

d){
}

{
}

Vi
ewAnswer

Answer
:c

Expl
anati
on:Thecodeshownabov eshowst wofuncti
ons.I
nboththecasesther
ightoper
andisr
eturned.Thi
sis
becauseeachfuncti
oni
sevaluat
edfrom lef
ttori
ght.Si
ncethelef
toper
andisfal
se,iti
sassumedthattheri
ght
operandmustbet r
ueandhencetherightoper
andisretur
nedineachoftheabov
ecase.
7.Whati
stheout
putoft
hecodeshownbel
ow?

adv
ert
isement

cl
assTr
uth:

pass

x=Tr
uth(
)

bool
(x)

a)pass

b)t
rue

c)f
alse

d)er
ror

Vi
ewAnswer

Answer
:b

Expl
anat
ion:I
fthet
rut
hmet
hodi
snotdef
ined,
theobj
ecti
sconsi
der
edt
rue.Hencet
heout
putoft
hecodeshown
abovei
strue.

8.Whati
stheout
putoft
hecodeshownbel
ow?

i
f(9<0)and(
0<-
9):

pr
int
("
hel
l
o")

el
i
f(9>0)orFal
se:

pr
int
("
good"
)

el
se:

pr
int
("
bad"
)

a)er
ror

b)hel
l
o

c)good

d)bad

Vi
ewAnswer
9.Whi
choft
hef
oll
owi
ngBool
eanexpr
essi
onsi
snotl
ogi
cal
l
yequi
val
entt
otheot
hert
hree?

a)not
(-
6<0or
-6>10)

b)-
6>=0and-
6<=10

c)not
(-
6<10or
-6==10)

d)not
(-
6>10or
-6==10)

Vi
ewAnswer

Answer
:d

Expl
anat
ion:
Theexpr
essi
onnot
(-
6<0or-
6>10)r
etur
nst
heout
putFal
se.

Theexpr
essi
on-
6>=0and-
6<=10r
etur
nst
heout
putFal
se.

Theexpr
essi
onnot
(-
6<10or-
6==10)r
etur
nst
heout
putFal
se.

Theexpr
essi
onnot
(-
6>10or-
6==10)r
etur
nst
heout
putTr
ue.

10.Theout
putoft
hel
i
neofcodeshownbel
owi
s:

not
(10<20)andnot
(10>30)

a)Tr
ue

b)Fal
se

c)Er
ror

d)Noout
put

Vi
ewAnswer

Answer
:b

Explanat
ion:Theexpressi
onnot
(10<20)ret
urnsfal
se.Theexpr
essi
onnot(
10>30)ret
urnst
rue.Theandoperat
ion
betweenf al
seandtrueret
urnsf
alse.Hencetheoutputi
sfal
sePyt
honQuesti
onsandAnswers–Adv anced
Formatti
ngTools

Thi
ssetofPy
thonMul
ti
pleChoi
ceQuest
ions&Answer
s(MCQs)f
ocuseson“
Adv
ancedFor
mat
ti
ngTool
s”.

1.Whati
stheout
putoft
hecodeshown?

l
=li
st(
'HELLO'
)
'
fi
rst
={0[
0]}
,thi
rd={
0[2]
}'
.f
ormat
(l
)

a)‘
fi
rst
=H,
thi
rd=L’

b)‘
fi
rst
=0,
thi
rd=2’

c)Er
ror

d)‘
fi
rst
=0,
thi
rd=L’

Vi
ewAnswer

Answer
:a

Explanati
on:I
nthecodeshownabove,
thevaluef
orf
ir
stissubst
it
utedbyl[
0],
thati
sHandt heval
ueforthi
rdi
s
substit
utedbyl[
2],
thati
sL.Hencet
heoutputoft
hecodeshownabov ei
s:‘
fi
rst=H,
thi
rd=L’
.Theli
stl
=[‘
H’,‘
E’
,‘
L’
,‘
L’
,

O’].

2.Whati
stheout
putoft
hecodeshownbel
ow?

l
=li
st(
'HELLO'
)

p=l
[0]
,l
[-
1],
l[
1:3]

'
a={
0},
b={
1},
c={
2}'
.
for
mat
(*p)

a)Er
ror

b)“
a=’
H’,
b=’
O’,
c=(
E,L)

c)“
a=H,
b=O,
c=[

E’,
‘L’
]

d)Junkv
alue

Vi
ewAnswer

Answer
:c

Explanati
on:I
nthecodeshownabove,
thevaluef
oraissubsti
tut
edbyl[
0],t
hati
s‘H’
,t
hevalueofbissubst
it
utedby
l
[-1]
,thati
s‘O’andtheval
ueforci
ssubst
it
utedbyl[
1:3]
.Heretheuseof*pist
ounpackatupl
eitemsint
oindi
vidual
functi
onarguments.

3.Fi
l
lint
hebl
anks:

Theformatti
ngmet
hod{
1:<10}r
epr
esent
sthe_
___
___
___
_posi
ti
onal
argument
,__
___
___
_just
if
iedi
na10char
act
er
widefi
eld.

a)f
ir
st,
right

b)second,
lef
t

c)f
ir
st,
lef
t
d)second,
right

Vi
ewAnswer

Answer
:b

Expl
anation:
Thef
ormat
ti
ngmet
hod{
1:<10}r
epr
esent
sthesecondposi
ti
onal
argument
,lef
tjust
if
iedi
na10char
act
er
widefi
eld.

4.Whati
stheout
putoft
hef
oll
owi
ngcode?

hex(
255)
,int
('
FF'
,16)
,0xFF

a)[
0xFF,
255,
16,
255]

b)(
‘0xf
f’
,155,
16,
255)

c)Er
ror

d)(
‘0xf
f’
,255,
255)

Vi
ewAnswer

Answer
:d

Expl
anati
on:Thecodeshownaboveconvert
sthevalue255i
ntohexadeci
mal
,thati
s,0xf
f.Thev
alue‘
FF’
int
oint
eger
.
Hencetheoutputoft
hecodeshownis:(
‘0xf
f’
,255,255)
.

5.Theout
putoft
het
wocodesshownbel
owi
sthesame.St
atewhet
hert
hisst
atementi
str
ueorf
alse.

bi
n((
2**
16)
-1)

'
{}
'.
for
mat
(bi
n((
2**
16)
-1)
)

a)Tr
ue

b)Fal
se

Vi
ewAnswer

Answer
:a

Expl
anat
ion:
Theout
putofbot
hoft
hecodesshownabov
eis‘
0b1111111111111111’
.Hencet
hest
atementi
str
ue.

6.Whati
stheout
putoft
hecodeshownbel
ow?

'
{a}
{b}
{a}
'.
for
mat
(a='
hel
l
o',
b='
wor
ld'
)
a)‘
hel
l
owor
ld’

b)‘
hel
l
o’‘
wor
ld’
‘hel
l
o’

c)‘
hel
l
owor
ldhel
l
o’

d)‘
hel
l
o’‘
hel
l
o’‘
wor
ld’

Vi
ewAnswer

Answer
:c

Expl
anat
ion:
Thecodeshownabov epri
ntst
hev al
uessubst
itut
edf
ora,b,a,i
nthesameorder
.Thi
soper
ati
oni
s
perf
ormedusingt
hef
ormatfunct
ion.Hencetheoutputoft
hecodeis:
‘hel
lowor
ldhel
l
o’.

7.Whati
stheout
putoft
hecodeshownbel
ow?

adv
ert
isement

D=di
ct(
p='
san'
,q='
foundr
y'
)

'
{p}
{q}
'.
for
mat
(**
D)

a)Er
ror

b)sanf
oundr
y

c)sanf
oundr
y

d){
‘san’
,‘
foundr
y’}

Vi
ewAnswer

Answer
:b

Expl
anat
ion:
Thecodeshownabov
epri
ntst
hev aluessubst
it
utedf
orpandqi
nthesameor
der
.Not
ethatt
her
eisno
bl
ankspacebet
weenpandq.Hencet
heoutputis:sanf
oundry.

8.Whati
stheout
putoft
hecodeshownbel
ow?

'
The{
}si
de{
1}{
2}'
.
for
mat
('
bri
ght
'
,'of
',
'l
if
e')

a)Er
ror

b)‘
Thebr
ightsi
deofl
i
fe’

c)‘
The{
bri
ght
}si
de{
of}{
li
fe}

d)Noout
put
Vi
ewAnswer

Answer
:a

Expl
anat
ion:
Thecodeshownabov
er esult
sinanerr
or.Thi
sisbecausewehaveswit
chedf
rom aut
omat
icf
iel
d
numberi
ngtomanualf
iel
dnumber
ing,thati
s,f
rom {
}to{1}
.Hencethiscoder
esul
tsi
nanerror
.

9.Theout
putoft
hecodeshownbel
owi
s:

'
{0:
f}
,{1:
2f}
,{2:
05.
2f}
'.
for
mat
(1.
23456,
1.23456,
1.23456)

a)Er
ror

b)‘
1.234560,
1.22345,
1.23’

c)Noout
put

d)‘
1.234560,
1.234560,
01.
23’

Vi
ewAnswer

Answer
:d

Explanat
ion:
Inthecodeshownabov e,var
iousfor
mat
ti
ngopt
ionsar
edi
spl
ayedusi
ngt
hef
ormatopt
ion.Hencet
he
outputofthi
scodeis:‘
1.234560,
1.234560,01.
23’

10.Whati
stheout
putoft
hecodeshownbel
ow?

'
%.2f
%s'
%(1.
2345,
99)

a)‘
1.2345’
,‘
99’

b)‘
1.2399’

c)‘
1.234599’

d)1.
23,
99

Vi
ewAnswer

Answer
:b

Expl
anati
on:
Inthiscode, wemustnot
icet
hatsincemult
ipl
evalueshav
enbeengi
ven,
theyshouldbeencl
osedina
tupl
e.Si
ncetheformatti
ngformati
s%.2f,
thevalue1.
2345isreducedt
otwodeci
malplaces.Hencet
heoutputoft
he
codeshownabov e:‘
1.2399’
.

11.Whati
stheout
putoft
hecodeshownbel
ow?
'
%s'
%((
1.23,
),
)

a)‘
(1.
23,
)’

b)1.
23,

c)(
,1.
23)

d)‘
1.23’

Vi
ewAnswer

Answer
:a

Explanati
on:Theformatti
ngexpressi
onaccept sei
therasinglesubst
it
uti
onval
ue,oratupl
eofoneormorei
tems.
Sincesinglei
tem canbegiveneit
herbyi t
selforwi
thint
het uple,
atupl
etobeformatt
edmustbeprovi
dedasatest
ed
tuple.Hencetheoutputofthecodeis:>>>‘%s’%((
1.23,
),
).

12.Whati
stheout
putoft
het
wocodesshownbel
ow?

'
{0}
'.
for
mat
(4.
56)

'
{0}
'.
for
mat
([
4.56,
]
)

a)‘
4.56’
,‘
4.56,

b)‘
4.56’
,‘
[4.
56]

c)4.
56,
[4.
56,
]

d)4.
56,
[4.
56,
]

Vi
ewAnswer

Answer
:b

Explanati
on:
Thecodeshownaboveshowsthef
ormatt
ingopti
ononthesameval
ue,
thati
s4.
56,
wher
eint
hesecond
case,theval
uei
senclosedi
nali
st.Hencet
heout
putofthecodeshownabov
eis:


4.56’
,‘
[4.
56]
’Py
thonQuest
ionsandAnswer
s–Decor
ator
s

Thi
ssetofPy
thonMul
ti
pleChoi
ceQuest
ions&Answer
s(MCQs)f
ocuseson“
Decor
ator
s”.

1.Whati
stheout
putoft
hecodeshownbel
ow?

defmk(
x):
defmk1(
):

pr
int
("
Decor
ated"
)

x(
)

r
etur
nmk1

defmk2(
):

pr
int
("
Ordi
nar
y")

p=mk(
mk2)

p(
)

a)Decor
ated

Decor
ated

b)Or
dinar
y

Or
dinar
y

c)Or
dinar
y

Decor
ated

d)Decor
ated

Or
dinar
y

Vi
ewAnswer

Answer
:d

Expl
anati
on:
Thecodeshownabov
efi
rstpr
int
sthewor
d“Decor
ated”andt
hen“
ordi
nar
y”.Hencet
heout
putoft
his
codeis:

Decor
ated

Or
dinar
y.

2.I
nthecodeshownbel
ow,
whi
chf
unct
ioni
sthedecor
ator
?

defmk(
x):

defmk1(
):

pr
int
("
Decor
ated"
)

x(
)

r
etur
nmk1
defmk2(
):

pr
int
("
Ordi
nar
y")

p=mk(
mk2)

p(
)

a)p(
)

b)mk(
)

c)mk1(
)

d)mk2(
)

Vi
ewAnswer

Answer
:b

Expl
anation:
Inthecodeshownabove,
thef
unct
ionmk(
)ist
hedecor
ator
.Thef
unct
ionwhi
chi
sget
ti
ngdecor
atedi
s
mk2().Theretur
nfunct
ioni
sgiv
enthenamep()
.

3.The___
___symbolal
ongwit
hthenameofthedecor
atorf
uncti
oncanbepl
acedabov
ethedef
ini
ti
onoft
hef
unct
ion
tobedecorat
edworksasanal
ter
natewayf
ordecorat
ingafunct
ion.

a)#

b)$

c)@

d)&

Vi
ewAnswer

Answer
:c

Explanat
ion:
The@ symbolal
ongwit
hthenameoft
hedecoratorfunct
ioncanbepl
acedabov
ethedef
ini
ti
onoft
he
functi
ontobedecor
atedworksasanal
ter
nat
ewayfordecor
atingafuncti
on.

4.Whati
stheout
putoft
hecodeshown?

defor
di(
):

pr
int
("
Ordi
nar
y")

or
di

or
di(
)

a)Addr
ess
Or
dinar
y

b)Er
ror

Addr
ess

c)Or
dinar
y

Or
dinar
y

d)Or
dinar
y

Addr
ess

Vi
ewAnswer

Answer
:a

Expl
anation:Thecodeshownabov er
etur
nst
headdr
essont
hef
unct
ionor
dif
ir
st,
aft
erwhi
cht
hewor
d“Or
dinar
y”i
s
pri
nted.Hencetheoutputoft
hiscodeis:

Addr
ess

Or
dinar
y.

5.Thet
wosni
ppet
sofcodesshownbel
owar
eequi
val
ent
.St
atewhet
hert
rueorf
alse.

CODE1

@f

deff
1()
:

pr
int
(“Hel
l
o”)

CODE2

deff
1()
:

pr
int
(“Hel
l
o”)

f
1=f
(f1)

a)Tr
ue

b)Fal
se

Vi
ewAnswer

Answer
:a

Explanat
ion:The@ symbol
canbeusedasanalt
ernat
ewayt ospecif
yaf unct
ionthatneedstobedecorat
ed.The
outputofthecodesshownabov
eisthesame.Hencetheyar
eequivalent
.Theref
orethisstat
ementi
strue.
6.Whati
stheout
putoft
hef
oll
owi
ngf
unct
ion?

deff
(p,
q):

r
etur
np%q

f
(0,
2)

f
(2,
0)

a)0

b)Zer
oDi
vi
sionEr
ror

Zer
oDi
vi
sionEr
ror

c)0

Zer
oDi
vi
sionEr
ror

d)Zer
oDi
vi
sionEr
ror

Vi
ewAnswer

Answer
:c

Expl
anat
ion:
Theoutputoff(
0,2)i
s0,si
nceo%2isequal
to0.Theout
putoft
hef
(2,
0)i
saZer
oDi
vi
sionEr
ror
.Wecan
makeuseofdecor
atorsinor
dertoav
oidthi
ser
ror.

7.Whati
stheout
putoft
hecodeshownbel
ow?

adv
ert
isement

deff
(x)
:

deff
1(a,
b):

pr
int
("
hel
l
o")

i
fb==0:

pr
int
("
NO"
)

r
etur
n

r
etur
nf(
a,b)

r
etur
nf1
@f

deff
(a,
b):

r
etur
na%b

f
(4,
0)

a)hel
l
o

NO

b)hel
l
o

Zer
oDi
vi
sionEr
ror

c)NO

d)hel
l
o

Vi
ewAnswer

Answer
:a

Explanat
ion:
Inthecodeshownabov
e,wehav
eusedadecor
atori
nor
dert
oav
oidt
heZer
oDi
vi
sionEr
ror
.Hencet
he
outputofthi
scodeis:

hel
l
o

NO.

8.Whatar
etheout
putoft
hecodeshownbel
ow?

deff
(x)
:

deff
1(*
args,
**kwar
gs)
:

pr
int
("
*"*5)

x(
*ar
gs,
**kwar
gs)

pr
int
("
*"*5)

r
etur
nf1

defa(
x):

deff
1(*
args,
**kwar
gs)
:

pr
int
("
%"*5)

x(
*ar
gs,
**kwar
gs)

pr
int
("
%"*5)
r
etur
nf1

@f

@a

defp(
m):

pr
int
(m)

p(
"hel
l
o")

a)*
***
*

%%%%%

hel
l
o

%%%%%

*
***
*

b)Er
ror

c)*
***
*%%%%%hel
l
o%%%%%*
***
*

d)hel
l
o

Vi
ewAnswer

Answer
:a

Expl
anat
ion:
Thecodeshownabov
eusesmul
ti
pledecor
ator
s.Theout
putoft
hiscodei
s:

*
***
*

%%%%%

hel
l
o

%%%%%

*
***
*

9.Thecodeshownabov
ecanwor
kwi
th_
___par
amet
ers.

deff
(x)
:

deff
1(*
args,
**kwar
gs)
:

pr
int
("
Sanf
oundr
y")

r
etur
nx(
*ar
gs,
**kwar
gs)

r
etur
nf1
a)2

b)1

c)anynumberof

d)0

Vi
ewAnswer

Answer
:c

Expl
anat
ion:
Thecodeshownabov
eshowsagener
aldecor
atorwhi
chcanwor
kwi
thanynumberofar
gument
s.

10.Whati
stheout
putoft
hecodeshownbel
ow?

deff
(x)
:

deff
1(*
args,
**kwar
gs)
:

pr
int
("
*",
5)

x(
*ar
gs,
**kwar
gs)

pr
int
("
*",
5)

r
etur
nf1

@f

defp(
m):

p(
m)

pr
int
("
hel
l
o")

a)*
***
*

hel
l
o

b)*
***
*

*
***
*

hel
l
o

c)*
***
*

d)hel
l
o

Vi
ewAnswer

Answer
:d
Expl
anati
on:I
nthecodeshownabov
e,wehav
enotpassedanypar
amet
ert
othef
unct
ionp.Hencet
heout
putoft
his
codeis:
hell
o.

11.Af
unct
ionwi
thpar
amet
erscannotbedecor
ated.St
atewhet
hert
rueorf
alse.

a)Tr
ue

b)Fal
se

Vi
ewAnswer

Answer
:a

Expl
anat
ion:
Anyf
unct
ion,
irr
espect
iveofwhet
herornoti
thaspar
amet
erscanbedecor
ated.Hencet
hest
atementi
s
fal
se.

12.I
dent
if
ythedecor
atori
nthesni
ppetofcodeshownbel
ow.

defsf
():

pass

sf=mk(
sf)

@f

defsf
():

r
etur
n

a)@f

b)f

c)sf
()

d)mk

Vi
ewAnswer

Answer
:d

Expl
anation:
Int
hecodeshownabove,@sfisnotadecoratorbutonl
yadecor
atorl
i
ne.The‘
@’sy
mbol
repr
esent
sthe
appl
icat
ionofadecor
ator
.Thedecor
atorherei
sthefuncti
onmk.

13.Whati
stheout
putoft
hecodeshownbel
ow?

cl
assA:

@st
ati
cmet
hod
defa(
x):

pr
int
(x)

A.
a(100)

a)Er
ror

b)War
ning

c)100

d)Noout
put

Vi
ewAnswer

Answer
:c

Expl
anati
on:Thecodeshownabov edemonstr
atesr
ebi
ndi
ngusi
ngast
ati
cmet
hod.Thi
scanbedonewi
thorwi
thout
adecorat
or.Theoutputoft
hiscodewil
lbe100.

14.Whati
stheout
putoft
hecodeshownbel
ow?

defd(
f):

defn(
*ar
gs)
:

r
etur
n'$'
+st
r(f
(*ar
gs)
)

r
etur
nn

@d

defp(
a,t
):

r
etur
na+a*
t

pr
int
(p(
100,
0))

a)100

b)$100

c)$0

d)0

Vi
ewAnswer

Answer
:b

Explanat
ion:Int
hecodeshownabove,t
hedecoratorhel
psust
opr
efi
xthedol
l
arsi
gnal
ongwi
tht
hev
alue.Si
ncet
he
secondar gumenti
szer
o,theout
putofthecodeis:$100.
15.Whati
stheout
putoft
hecodeshownbel
ow?

defc(
f):

defi
nner
(*ar
gs,
**kar
gs)
:

i
nner
.co+=1

r
etur
nf(
*ar
gs,
**kar
gs)

i
nner
.co=0

r
etur
ninner

@c

deff
nc(
):

pass

i
f__
name_
_=='
__mai
n__
':

f
nc(
)

f
nc(
)

f
nc(
)

pr
int
(fnc.
co)

a)4

b)3

c)0

d)1

Vi
ewAnswer

Answer
:b

Explanat
ion:
Thecodeshownaboveret
urnst
henumberoft
imesagivenf
unct
ionhasbeencal
l
ed.Hencet
heout
put
ofthiscodeis:
3Py
thonQuest
ionsandAnswers–Whi
leandForLoops–1

Thi
ssetofPy
thonMul
ti
pleChoi
ceQuest
ions&Answer
s(MCQs)f
ocuseson“
Whi
l
eandForLoops”
.

1.Whati
stheout
putoft
hef
oll
owi
ng?

x=[
'
ab'
,'
cd'
]
f
ori
inx:

i
.upper
()

pr
int
(x)

a)[

ab’
,‘
cd’
]
.

b)[

AB’
,‘
CD’
]
.

c)[
None,
None]
.

d)noneoft
hement
ioned

Vi
ewAnswer

Answer
:a

Expl
anat
ion:
Thef
unct
ionupper
()doesnotmodi
fyast
ri
ngi
npl
ace,
itr
etur
nsanewst
ri
ngwhi
chi
sn’
tbei
ngst
ored
anywher
e.

2.Whati
stheout
putoft
hef
oll
owi
ng?

x=[
'
ab'
,'
cd'
]

f
ori
inx:

x.
append(
i.
upper
())

pr
int
(x)

a)[

AB’
,‘
CD’
]
.

b)[

ab’
,‘
cd’
,‘
AB’
,‘
CD’
]
.

c)[

ab’
,‘
cd’
]
.

d)noneoft
hement
ioned

Vi
ewAnswer

Answer
:d

Expl
anat
ion:
Thel
oopdoesnott
ermi
nat
easnewel
ement
sar
ebei
ngaddedt
othel
i
sti
neachi
ter
ati
on.

3.Whati
stheout
putoft
hef
oll
owi
ng?

i
=1

whi
l
eTr
ue:
i
fi%3==0:

br
eak

pr
int
(i
)

i
+=1

a)12

b)123

c)er
ror

d)noneoft
hement
ioned

Vi
ewAnswer

Answer
:c

Expl
anat
ion:
Synt
axEr
ror
,ther
eshoul
dn’
tbeaspacebet
ween+and=i
n+=.

4.Whati
stheout
putoft
hef
oll
owi
ng?

i
=1

whi
l
eTr
ue:

i
fi%0O7==0:

br
eak

pr
int
(i
)

i
+=1

a)123456

b)1234567

c)er
ror

d)noneoft
hement
ioned

Vi
ewAnswer

Answer
:a

Expl
anat
ion:
Cont
rol
exi
tst
hel
oopwheni
becomes7.

5.Whati
stheout
putoft
hef
oll
owi
ng?
i
=5

whi
l
eTr
ue:

i
fi%0O11==0:

br
eak

pr
int
(i
)

i
+=1

a)5678910

b)5678

c)56

d)er
ror

Vi
ewAnswer

Answer
:b

Expl
anat
ion:
0O11i
sanoct
alnumber
.

6.Whati
stheout
putoft
hef
oll
owi
ng?

i
=5

whi
l
eTr
ue:

i
fi%0O9==0:

br
eak

pr
int
(i
)

i
+=1

a)5678

b)56789

c)56789101112131415….

d)er
ror

Vi
ewAnswer

Answer
:d
Expl
anat
ion:
9isn’
tal
l
owedi
nanoct
alnumber
.

adv
ert
isement

7.Whati
stheout
putoft
hef
oll
owi
ng?

i
=1

whi
l
eTr
ue:

i
fi%2==0:

br
eak

pr
int
(i
)

i
+=2

a)1

b)12

c)123456…

d)1357911…

Vi
ewAnswer

Answer
:d

Expl
anat
ion:
Thel
oopdoesnott
ermi
nat
esi
ncei
isnev
eranev
ennumber
.

8.Whati
stheout
putoft
hef
oll
owi
ng?

i
=2

whi
l
eTr
ue:

i
fi%3==0:

br
eak

pr
int
(i
)

i
+=2

a)246810…

b)24

c)23

d)er
ror
Vi
ewAnswer

Answer
:b

Expl
anat
ion:
Thenumber
s2and4ar
epr
int
ed.Thenextv
alueofi
is6whi
chi
sdi
vi
sibl
eby3andhencecont
rol
exi
ts
thel
oop.

9.Whati
stheout
putoft
hef
oll
owi
ng?

i
=1

whi
l
eFal
se:

i
fi%2==0:

br
eak

pr
int
(i
)

i
+=2

a)1

b)1357…

c)1234…

d)noneoft
hement
ioned

Vi
ewAnswer

Answer
:d

Expl
anat
ion:
Cont
rol
doesnotent
ert
hel
oopbecauseofFal
se.

10.Whati
stheout
putoft
hef
oll
owi
ng?

Tr
ue=Fal
se

whi
l
eTr
ue:

pr
int
(Tr
ue)

br
eak

a)Tr
ue

b)Fal
se

c)None
d)noneoft
hement
ioned

Vi
ewAnswer

Answer
:d

Expl
anat
ion:Sy
ntaxEr
ror
,Tr
uei
sakey
wor
dandi
t’
sval
uecannotbechanged.Py
thonQuest
ionsandAnswer
s–Whi
l
e
andForLoops–2

Thi
ssetofAdv
ancedPy
thonQuest
ions&Answer
sfocuseson“
Whi
l
eandForLoops–2”
.

1.Whati
stheout
putoft
hef
oll
owi
ng?

i
=0

whi
l
ei<5:

pr
int
(i
)

i
+=1

i
fi==3:

br
eak

el
se:

pr
int
(0)

a)0120

b)012

c)er
ror

d)noneoft
hement
ioned

Vi
ewAnswer

Answer
:b

Expl
anat
ion:
Theel
separ
tisnotexecut
edi
fcont
rol
breaksoutoft
hel
oop.

2.Whati
stheout
putoft
hef
oll
owi
ng?

i
=0

whi
l
ei<3:
pr
int
(i
)

i
+=1

el
se:

pr
int
(0)

a)01230

b)0120

c)012

c)er
ror

Vi
ewAnswer

Answer
:b

Expl
anat
ion:
Theel
separ
tisexecut
edwhent
hecondi
ti
oni
nthewhi
l
est
atementi
sfal
se.

3.Whati
stheout
putoft
hef
oll
owi
ng?

x="
abcdef
"

whi
l
eii
nx:

pr
int
(i
,end=""
)

a)abcdef

b)abcdef

c)i
iii
ii…

d)er
ror

Vi
ewAnswer

Answer
:d

Expl
anat
ion:
NameEr
ror
,ii
snotdef
ined.

4.Whati
stheout
putoft
hef
oll
owi
ng?

x="
abcdef
"

i
="i
"

whi
l
eii
nx:
pr
int
(i
,end=""
)

a)noout
put

b)i
iii
ii…

c)abcdef

d)abcdef

Vi
ewAnswer

Answer
:a

Expl
anat
ion:
“i”i
snoti
n“abcdef
”.

5.Whati
stheout
putoft
hef
oll
owi
ng?

x="
abcdef
"

i
="a"

whi
l
eii
nx:

pr
int
(i
,end=""
)

a)noout
put

b)i
iii
ii…

c)aaaaaa…

d)abcdef

Vi
ewAnswer

Answer
:c

Expl
anat
ion:
Ast
hev
alueofi
orxi
sn’
tchangi
ng,
thecondi
ti
onwi
l
lal
way
sev
aluat
etoTr
ue.

6.Whati
stheout
putoft
hef
oll
owi
ng?

x="
abcdef
"

i
="a"

whi
l
eii
nx:

pr
int
('
i'
,end=""
)

a)noout
put
b)i
iii
ii…

c)aaaaaa…

d)abcdef

Vi
ewAnswer

Answer
:b

Expl
anat
ion:
Ast
hev
alueofi
orxi
sn’
tchangi
ng,
thecondi
ti
onwi
l
lal
way
sev
aluat
etoTr
ue.

adv
ert
isement

7.Whati
stheout
putoft
hef
oll
owi
ng?

x="
abcdef
"

i
="a"

whi
l
eii
nx:

x=x[
:-
1]

pr
int
(i
,end=""
)

a)i
iii
ii

b)aaaaaa

c)aaaaa

d)noneoft
hement
ioned

Vi
ewAnswer

Answer
:b

Expl
anat
ion:
Thest
ri
ngxi
sbei
ngshor
tenedbyonechar
act
eri
neachi
ter
ati
on.

8.Whati
stheout
putoft
hef
oll
owi
ng?

x="
abcdef
"

i
="a"

whi
l
eii
nx[
:-
1]:

pr
int
(i
,end=""
)
a)aaaaa

b)aaaaaa

c)aaaaaa…

d)a

Vi
ewAnswer

Answer
:c

Expl
anat
ion:
Str
ingxi
snotbei
ngal
ter
edandi
isi
nx[
:-
1].

9.Whati
stheout
putoft
hef
oll
owi
ng?

x="
abcdef
"

i
="a"

whi
l
eii
nx:

x=x[
1:]

pr
int
(i
,end=""
)

a)aaaaaa

b)a

c)noout
put

d)er
ror

Vi
ewAnswer

Answer
:b

Expl
anat
ion:
Thest
ri
ngxi
sbei
ngshor
tenedbyonechar
act
eri
neachi
ter
ati
on.

10.Whati
stheout
putoft
hef
oll
owi
ng?

x="
abcdef
"

i
="a"

whi
l
eii
nx[
1:]
:

pr
int
(i
,end=""
)

a)aaaaaa
b)a

c)noout
put

d)er
ror

Vi
ewAnswer

Answer
:c

Expl
anat
ion:
iisnoti
nx[
1:]
.

You might also like