PYTHON测试题Word格式文档下载.docx
《PYTHON测试题Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《PYTHON测试题Word格式文档下载.docx(31页珍藏版)》请在冰豆网上搜索。
B.4
C.5
D.6
E.7
8.whatgetsprinted?
Assumingpythonversion3.x(C)
print(type(1/2))
9.Whatgetsprinted?
(C)
d=lambdap:
p*2
t=lambdap:
p*3
x=2
x=d(x)
x=t(x)
printx
A.7
B.12
C.24
D.36
E.48
10.Whatgetsprinted?
x=4.5
y=2
printx//y
A.2.0
B.2.25
C.9.0
D.20.25
E.21
11.Whatgetsprinted?
nums=set([1,1,2,3,3,3,4])
printlen(nums)
A.1
B.2
C.4
D.5
12.Whatgetsprinted?
x=True
y=False
z=False
ifxoryandz:
print"
yes"
else:
no"
A.yes
B.no
C.failstocompile
13.Whatgetsprinted?
ifnotxory:
print1
elifnotxornotyandz:
print2
elifnotxoryornotyandx:
print3
print4
C.3
D.4
14.IfPYTHONPATHissetintheenvironment,whichdirectoriesaresearchedformodules?
A)PYTHONPATHdirectory
B)currentdirectory
C)homedirectory
D)installationdependentdefaultpath
A.Aonly
B.AandD
C.A,B,andC
D.A,B,andD
E.A,B,C,andD
15.Inpython2.6orearlier,thecodewillprinterrortype1ifaccessSecureSystemraisesanexceptionofeitherAccessErrortypeorSecurityErrortype(B)
try:
accessSecureSystem()
exceptAccessError,SecurityError:
errortype1"
continueWork()
A.true
B.false
16.Thefollowingcodewillsuccessfullyprintthedaysandthenthemonths(B)
daysOfWeek=['
Monday'
'
Tuesday'
Wednesday'
Thursday'
Friday'
Saturday'
Sunday'
]
months=['
Jan'
\
Feb'
Mar'
Apr'
May'
Jun'
Jul'
Aug'
Sep'
Oct'
Nov'
Dec'
print"
DAYS:
%s,MONTHS%s"
%
(daysOfWeek,months)
17.Assumingpython2.6whatgetsprinted?
f=None
foriinrange(5):
withopen("
data.txt"
"
w"
)asf:
ifi>
2:
break
printf.closed
A.True
B.False
C.None
18.Whatgetsprinted?
counter=1
defdoLotsOfStuff():
globalcounter
foriin(1,2,3):
counter+=1
doLotsOfStuff()
printcounter
B.3
D.7
E.noneoftheabove
19.Whatgetsprinted?
printr"
\nwoow"
A.newlinethenthestring:
woow
B.thetextexactlylikethis:
r"
C.thetextlikeexactlylikethis:
\nwoow
D.theletterrandthennewlinethenthetext:
E.theletterrthenthetextlikethis:
nwoow
20.Whatgetsprinted?
(B)
hello"
world'
A.ononelinethetext:
helloworld
B.ononelinethetext:
helloworld
C.helloononelineandworldonthenextline
D.syntaxerror,thispythonprogramwillnotrun
21.Whatgetsprinted?
(E)
\x48\x49!
"
A.\x48\x49!
B.4849
C.4849!
D.4849!
E.HI!
22.Whatgetsprinted?
print0xA+0xa
A.0xA+0xa
B.0xA0xa
C.14
D.20
E.0x20
23.Whatgetsprinted?
classparent:
def__init__(self,param):
self.v1=param
classchild(parent):
self.v2=param
obj=child(11)
%d%d"
%(obj.v1,obj.v2)
A.NoneNone
B.None11
C.11None
D.1111
E.Errorisgeneratedbyprogram
24.Whatgetsprinted?
kvps={"
user"
"
bill"
password"
hillary"
}
printkvps['
password'
A.user
B.bill
C.password
D.hillary
E.Nothing.Pythonsyntaxerror
25.Whatgetsprinted?
66%on1871timesasked
classAccount:
def__init__(self,id):
self.id=id
id=666
acc=Account(123)
printacc.id
A.None
B.123
C.666
D.SyntaxError,thisprogramwillnotrun
26.Whatgetsprinted?
name="
snowstorm"
%s"
%name[6:
8]
A.st
B.sto
C.to
D.tor
E.SyntaxError
27.Whatgetsprinted?
name[5]='
X'
printname
A.snowstorm
B.snowXstorm
C.snowXtorm
D.ERROR,thiscodewillnotrun
28.Whichnumbersareprinted?
foriinrange
(2):
printi
foriinrange(4,6):
A.2,4,6
B.0,1,2,4,5,6
C.0,1,4,5
D.0,1,4,5,6,7,8,9
E.1,2,4,5,6
29.Whatsequenceofnumbersisprinted?
values=[1,2,1,3]
nums=set(values)
defcheckit(num):
ifnuminnums:
returnTrue
else:
returnFalse
foriinfilter(checkit,values):
A.123
B.1213
C.12131213
D.11112233
30.Whatsequenceofnumbersisprinted?
values=[2,3,2,4]
defmy_transformation(num):
returnnum**2
foriinmap(my_transformation,values):
A.2324
B.4648
C.11.512
D.1112
E.49416
31.Whatnumbersgetprinted(C)
importpickle
classaccount:
def__init__(self,id,balance):
self.id=id
self.balance=balance
defdeposit(self,amount):
self.balance+=amount
defwithdraw(self,amount):
self.balance-=amount
myac=account('
123'
100)
myac.deposit(800)
myac.withdraw(500)
fd=open("
archive"
)
pickle.dump(myac,fd)
fd.close()
myac.deposit(200)
printmyac.balance
r"
myac=pickle.load(fd)
A.500300
B.500500
C.600400
D.600600
E.300500
32.Whatgetsprintedbythecodesnippetbelow?
importmath
printmath.floor(5.5)
A.5
B.5.0
C.5.5
E.6.0
33.Whatgetsprintedbythecodebelow?
classPerson:
obama=Person(100)
obama.__dict__['
age'
]=49
printobama.age+len(obama.__dict__)
C.49
D.50
E.51
34.Whatgetsprinted?
x="
foo"
printx+y
A.foo
B.foofoo
C.foo2
D.2
E.Anexceptionisthrown
35.Whatgetsprinted?
defsimpleFunction():
"
Thisisacoolsimplefunctionthatreturns1"
return1
printsimpleFunction.__doc__[10:
14]
A.simpleFunction
B.simple
C.func
D.funtion
E.cool
36.Whatdoesthecodebelowdo?
A.Changesthelocationthatthepythonexecutableisrunfrom
B.Changesthecurrentworkingdirectory
C.Addsanewdirectorytoseachforpythonmodulesthatareimported
D.Removesalldirectoriesformods
E.Changesthelocationwheresub-processesaresearchedforaftertheyarelaunched
37.Whatgetsprinted?
importre
sum=0
pattern='
back'
ifre.match(pattern,'
backup.txt'
):
sum+=1
text.back'
sum+=2
ifre.search(pattern,'
sum+=4
sum+=8
printsum
A.3
B.7
C.13
D.14
E.15
38.Whichofthefollowingprintstatementswillprintallthenamesinthelistonaseperateline(A)
names=['
Ramesh'
'
Rajesh'
Roger'
Ivan'
Nico'
A.print"
\n"
.join(names)
B.printnames.join("
)
C.printnames.concatenate("
D.printnames.append("
E.printnames.join("
%s\n"
names)
39.Trueorfalse?
Codeindentationmustbe4spaceswhencreatingacodeblock?
iferror:
#fourspacesofindentareusedtocreatetheblock
%msg
40.Assumingthefilenameforthecodebelowis/usr/lib/python/person.py
andtheprogramisrunas:
python/usr/lib/python/person.py
Whatgetsprinted?
def__init__(self):
defgetAge(self):
print__name__
p=Person()
p.getAge()
A.Person
B.getAge
C.
D.__main__
41.Whatgetsprinted(B)
foo={}
printtype(foo)
A.set
B.dict
C.list
D.tuple
E.object
42.Whatgetsprinted?
foo=(3,4,5)
A.int
B.list
C.tuple
D.dict
E.set
43.Whatgetsprinted?
country_counter={}
defaddone(country):
ifcountryincountry_counter:
country_counter[country]+=1
country_counter[country]=1
addone('
China'
Japan'
china'
printlen(country_counter)
A.0
B.1
C.2
D.3
E.4
44.Whatgetsprinted?
confusion={}
confusion[1]=1
confusion['
1'
]=2
confusion[1]+=1
forkinconfusion:
sum+=confusion[k]
E.5
45.Whatgetsprinted?
confusion[1.0]=4
A.2
C.6
46.Whatgetsprinted?
boxes={}
jars={}
crates={}
boxes['
cereal'
]=1
candy'
jars['
honey'
]=4
crates['
boxes'
]=boxes
jars'
]=jars
printlen(crates[boxes])
47.Whatgetsprinted?
numberGames={}
numberGames[(1,2,4)]=8
numberGames[(4,2,1)]=10
numberGames[(1,2)]=12
forkinnumberGames:
sum+=numberGames[k]
printlen(numberGames)+sum
A.8
D.30
E.33
48.Whatgetsprinted?
foo={1:
'
2:
2'
3:
3'
printlen(foo)
49.Whatgetsprinted?
delfoo[1]
foo[1]='
10'
delfoo[2]