版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
...wd...
...wd...
...wd...
1.whatdoesthefollowingcodedo?〔B〕
defa(b,c,d):pass
A.definesalistandinitializesit
B.definesafunction,whichdoesnothing
C.definesafunction,whichpassesitsparametersthrough
D.definesanemptyclass
2.whatgetsprinted?Assumingpythonversion2.x(A)
printtype(1/2)
A.<type'int'>
B.<type'number'>
C.<type'float'>
D.<type'double'>
E.<type'tuple'>
3.whatistheoutputofthefollowingcode?〔E〕
printtype([1,2])
A.<type'tuple'>
B.<type'int'>
C.<type'set'>
D.<type'complex'>
E.<type'list'>
4.whatgetsprinted?〔C〕
deff():pass
printtype(f())
A.<type'function'>
B.<type'tuple'>
C.<type'NoneType'>
D.<type'str'>
E.<type'type'>
5.whatshouldthebelowcodeprint?(A)
printtype(1J)
A.<type'complex'>
B.<type'unicode'>
C.<type'int'>
D.<type'float'>
E.<type'dict'>
6.whatistheoutputofthefollowingcode?(D)
printtype(lambda:None)
A.<type'NoneType'>
B.<type'tuple'>
C.<type'type'>
D.<type'function'>
E.<type'bool'>
7.whatistheoutputofthebelowprogram?(D)
a=[1,2,3,None,(),[],]
printlen(a)
A.syntaxerror
B.4
C.5
D.6
E.7
8.whatgetsprinted?Assumingpythonversion3.x(C)
print(type(1/2))
A.<type'int'>
B.<type'number'>
C.<type'float'>
D.<type'double'>
E.<type'tuple'>
9.Whatgetsprinted?(C)
d=lambdap:p*2
t=lambdap:p*3
x=2
x=d(x)
x=t(x)
x=d(x)
printx
A.7
B.12
C.24
D.36
E.48
10.Whatgetsprinted?(A)
x=4.5
y=2
printx//y
A.2.0
B.2.25
C.9.0
D.20.25
E.21
11.Whatgetsprinted?(C)
nums=set([1,1,2,3,3,3,4])
printlen(nums)
A.1
B.2
C.4
D.5
E.7
12.Whatgetsprinted?(A)
x=True
y=False
z=False
ifxoryandz:
print"yes"
else:
print"no"
A.yes
B.no
C.failstocompile
13.Whatgetsprinted?(C)
x=True
y=False
z=False
ifnotxory:
print1
elifnotxornotyandz:
print2
elifnotxoryornotyandx:
print3
else:
print4
A.1
B.2
C.3
D.4
14.IfPYTHONPATHissetintheenvironment,whichdirectoriesaresearchedformodules?(D)
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:
print"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)
A.true
B.false
17.Assumingpython2.6whatgetsprinted?(A)
f=None
foriinrange(5):
withopen("data.txt","w")asf:
ifi>2:
break
printf.closed
A.True
B.False
C.None
18.Whatgetsprinted?(C)
counter=1
defdoLotsOfStuff():
globalcounter
foriin(1,2,3):
counter+=1
doLotsOfStuff()
printcounter
A.1
B.3
C.4
D.7
E.noneoftheabove
19.Whatgetsprinted?(C)
printr"\nwoow"
A.newlinethenthestring:woow
B.thetextexactlylikethis:r"\nwoow"
C.thetextlikeexactlylikethis:\nwoow
D.theletterrandthennewlinethenthetext:woow
E.theletterrthenthetextlikethis:nwoow
20.Whatgetsprinted?(B)
print"hello"'world'
A.ononelinethetext:helloworld
B.ononelinethetext:helloworld
C.helloononelineandworldonthenextline
D.syntaxerror,thispythonprogramwillnotrun
21.Whatgetsprinted?(E)
print"\x48\x49!"
A.\x48\x49!
B.4849
C.4849!
D.4849!
E.HI!
22.Whatgetsprinted?(D)
print0xA+0xa
A.0xA+0xa
B.0xA0xa
C.14
D.20
E.0x20
23.Whatgetsprinted?(E)
classparent:
def__init__(self,param):
self.v1=param
classchild(parent):
def__init__(self,param):
self.v2=param
obj=child(11)
print"%d%d"%(obj.v1,obj.v2)
A.NoneNone
B.None11
C.11None
D.1111
E.Errorisgeneratedbyprogram
24.Whatgetsprinted?(E)
kvps={"user","bill","password","hillary"}
printkvps['password']
A.user
B.bill
C.password
D.hillary
E.Nothing.Pythonsyntaxerror
25.Whatgetsprinted?(B)
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?(C)
name="snowstorm"
print"%s"%name[6:8]
A.st
B.sto
C.to
D.tor
E.SyntaxError
27.Whatgetsprinted?(D)
name="snowstorm"
name[5]='X'
printname
A.snowstorm
B.snowXstorm
C.snowXtorm
D.ERROR,thiscodewillnotrun
28.Whichnumbersareprinted?(C)
foriinrange(2):
printi
foriinrange(4,6):
printi
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?(B)
values=[1,2,1,3]
nums=set(values)
defcheckit(num):
ifnuminnums:
returnTrue
else:
returnFalse
foriinfilter(checkit,values):
printi
A.123
B.1213
C.12131213
D.11112233
E.SyntaxError
30.Whatsequenceofnumbersisprinted?(E)
values=[2,3,2,4]
defmy_transformation(num):
returnnum**2
foriinmap(my_transformation,values):
printi
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","w")
pickle.dump(myac,fd)
fd.close()
myac.deposit(200)
printmyac.balance
fd=open("archive","r")
myac=pickle.load(fd)
fd.close()
printmyac.balance
A.500300
B.500500
C.600400
D.600600
E.300500
32.Whatgetsprintedbythecodesnippetbelow?(B)
importmath
printmath.floor(5.5)
A.5
B.5.0
C.5.5
D.6
E.6.0
33.Whatgetsprintedbythecodebelow?(E)
classPerson:
def__init__(self,id):
self.id=id
obama=Person(100)
obama.__dict__['age']=49
printobama.age+len(obama.__dict__)
A.1
B.2
C.49
D.50
E.51
34.Whatgetsprinted?(E)
x="foo"
y=2
printx+y
A.foo
B.foofoo
C.foo2
D.2
E.Anexceptionisthrown
35.Whatgetsprinted?(E)
defsimpleFunction():
"Thisisacoolsimplefunctionthatreturns1"
return1
printsimpleFunction.__doc__[10:14]
A.simpleFunction
B.simple
C.func
D.funtion
E.cool
36.Whatdoesthecodebelowdo?(C)
sys.path.append('/root/mods')
A.Changesthelocationthatthepythonexecutableisrunfrom
B.Changesthecurrentworkingdirectory
C.Addsanewdirectorytoseachforpythonmodulesthatareimported
D.Removesalldirectoriesformods
E.Changesthelocationwheresub-processesaresearchedforaftertheyarelaunched
37.Whatgetsprinted?(C)
importre
sum=0
pattern='back'
ifre.match(pattern,'backup.txt'):
sum+=1
ifre.match(pattern,'text.back'):
sum+=2
ifre.search(pattern,'backup.txt'):
sum+=4
ifre.search(pattern,'text.back'):
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("\n")
C.printnames.concatenate("\n")
D.printnames.append("\n")
E.printnames.join("%s\n",names)
39.Trueorfalse?Codeindentationmustbe4spaceswhencreatingacodeblock?(B)
iferror:
#fourspacesofindentareusedtocreatetheblock
print"%s"%msg
A.True
B.False
40.Assumingthefilenameforthecodebelowis/usr/lib/python/person.py
andtheprogramisrunas:
python/usr/lib/python/person.py
Whatgetsprinted?(D)
classPerson:
def__init__(self):
pass
defgetAge(self):
print__name__
p=Person()
p.getAge()
A.Person
B.getAge
C.usr.lib.python.person
D.__main__
E.Anexceptionisthrown
41.Whatgetsprinted(B)
foo={}
printtype(foo)
A.set
B.dict
C.list
D.tuple
E.object
42.Whatgetsprinted?(C)
foo=(3,4,5)
printtype(foo)
A.int
B.list
C.tuple
D.dict
E.set
43.Whatgetsprinted?(D)
country_counter={}
defaddone(country):
ifcountryincountry_counter:
country_counter[country]+=1
else:
country_counter[country]=1
addone('China')
addone('Japan')
addone('china')
printlen(country_counter)
A.0
B.1
C.2
D.3
E.4
44.Whatgetsprinted?(D)
confusion={}
confusion[1]=1
confusion['1']=2
confusion[1]+=1
sum=0
forkinconfusion:
sum+=confusion[k]
printsum
A.1
B.2
C.3
D.4
E.5
45.Whatgetsprinted?(C)
confusion={}
confusion[1]=1
confusion['1']=2
confusion[1.0]=4
sum=0
forkinconfusion:
sum+=confusion[k]
printsum
A.2
B.4
C.6
D.7
E.Anexceptionisthrown
46.Whatgetsprinted?(E)
boxes={}
jars={}
crates={}
boxes['cereal']=1
boxes['candy']=2
jars['honey']=4
crates['boxes']=boxes
crates['jars']=jars
printlen(crates[boxes])
A.1
B.2
C.4
D.7
E.Anexceptionisthrown
47.Whatgetsprinted?(E)
numberGames={}
numberGames[(1,2,4)]=8
numberGames[(4,2,1)]=10
numberGames[(1,2)]=12
sum=0
forkinnumberGames:
sum+=numberGames[k]
printlen(numberGames)+sum
A.8
B.12
C.24
D.30
E.33
48.Whatgetsprinted?(A)
foo={1:'1',2:'2',3:'3'}
foo={}
printlen(foo)
A.0
B.1
C.2
D.3
E.Anexceptionisthrown
49.Whatgetsprinted?(B)
foo={1:'1',2:'2',3:'3'}
delfoo[1]
foo[1]='10'
delfoo[2]
printlen(foo)
A.1
B.2
C.3
D.4
E.Anexceptionisthrown
50.Whatgetsprinted?(E)
names=['Amir','Barry','Chales','Dao']
printnames[-1][-1]
A.A
B.r
C.Amir
D.Dao
E.o
51.Whatgetsprinted?(B)
names1=['Amir','Barry','Chales','Dao']
names2=names1
names3=names1[:]
names2[0]='Alice'
names3[1]='Bob'
sum=0
forlsin(names1,names2,names3):
ifls[0]=='Alice':
sum+=1
ifls[1]=='Bob':
sum+=10
printsum
A.11
B.12
C.21
D.22
E.33
52.Whatgetsprinted?(E)
names1=['Amir','Barry','Chales','Dao']
loc=names1.index("Edward")
printloc
A.-1
B.0
C.4
D.Edward
E.Anexceptionisthrown
53.Whatgetsprinted?(B)
names1=['Amir','Barry','Chales','Dao']
if'amir'innames1:
print1
else:
print2
A.1
B.2
C.Anexceptionisthrown
54.Whatgetsprinted?(C)
names1=['Amir','Barry','Chales','Dao']
names2=[name.lower()fornameinnames1]
printnames2[2][0]
A.i
B.a
C.c
D.C
E.Anexceptionisthrown
55.Whatgetsprinted?(B)
numbers=[1,2,3,4]
numbers.append([5,6,7,8])
printlen(numbers)
A.4
B.5
C.8
D.12
E.Anexceptionisthrown
56.Whichofthefollowingdatastructurescanbeusedwiththe"in"operatortocheckifanitemisinthedatastructure?(E)
A.list
B.set
C.dictionary
D.Noneoftheabove
E.Alloftheabove
57.Watgetsprinted?(D)
list1=[1,2,3,4]
list2=[5,6,7,8]
printlen(list1+list2)
A.2
B.4
C.5
D.8
E.Anexceptionisthrown
58.Whatgetsprinted?(C)
defaddItem(listParam):
listParam+=[1]
mylist=[1,2,3,4]
addItem(mylist)
printlen(mylist)
A.1
B.4
C.5
D.8
E.Anexceptionisthrown
59.Whatgetsprinted?(E)
my_tuple=(1,2,3,4)
my_tuple.append((5,6,7))
printlen(my_tuple)
A.1
B.2
C.5
D.7
E.Anexceptionisthrown
60.Whatgetsprinted?(B)
a=1
b=2
a,b=b,a
print"%d%d"%(a,b)
A.12
B.21
C.Anexceptionisthrown
D.Thisprogramhasundefinedbehavior
61.Whatgetsprinted?(A)
defprint_header(str):
print"+++%s+++"%str
print_header.category=1
print_header.text="someinfo"
print_header("%d%s"%\
(print_header.category,print_header.text))
A.+++1someinfo+++
B.+++%s+++
C.1
D.someinfo
62.Whatgetsprinted?(C)
defdostuff(param1,*param2):
printtype(param2)
dostuff('apples','bananas','cherry','dates')
A.str
B.int
C.tuple
D.list
E.dict
63.Whatgetsprinted?〔E〕
defdostuff(param1,**param2):
printtype(param2)
dostuff('capitals',Arizona='Phoenix',
California='Sacramento',Texas='Austin')
A.in
B.str
C.tuple
D.list
E.dict
64.Whatgetsprinted?(B)
defmyfunc(x,y,z,a):
printx+y
nums=[1,2,3,4]
myfunc(*nums)
A.1
B.3
C.6
D.10
E.Anexceptionisthrown
65.Howdoyoucreateapackagesothatthefollowingreferencewillwork?(C)
p=mytools.myparser.MyParser()
A.Declarethemyparserpackageinmytools.py
B.Createan__init__.pyinthehomedir
C.Insidethemytoolsdircreatea__init__.py
D.Createamyparser.pydirectoryinsidethemytoolsdirectory
E.Thiscannotbedone
66.Whatgetsprinted?(E)
classA:
def__init__(self,a,b,c):
self.x=a+b+c
a=A(1,2,3)
b=getattr(a,'x')
setattr(a,'x',b+1)
printa.x
A.1
B.2
C.3
D.6
E.7
67.Whatgetsprinted?(E)
classNumFactory:
def__init__(self,n):
self.val=n
deftimesTwo(self):
self.val*=2
defplusTwo(self):
self.val+=2
f=NumFactory(2)
formindir(f):
mthd=getattr(f,m)
ifcallable(mthd):
mthd()
printf.val
A.2
B.4
C.6
D.8
E.Anexceptionisthrown
68.Whatgetsprinted?(A)
one=chr(104)
two=chr(105)
print"%s%s"%(one,two)
A.hi
B.h
C.Insidethemytoolsdircreatea__init__.pyandmyparser.py
D.104105
E.104
69.Whatgetsprinted?(A)
x=0
y=1
a=cmp(x,y)
ifa<x:
print"a"
elifa==x:
print"b"
else:
print"c"
A.a
B.b
C.c
70.Whatgetsprinted?(C)
x=1
y="2"
z=3
sum=0
foriin(x,y,z):
ifisinstance(i,int):
sum+=i
printsum
A.2
B.3
C.4
D.6
E.Anexceptionisthrown
71.Whatgetsprinted(withpythonversion2.X)assumingtheuserentersthefollowingattheprompt?(D)
#:foo
a=input("#:")
printa
A.f
B.foo
C.#:foo
D.Anexceptionisthrown
72.Whatgetsprinted?(C)
x=sum(range(5))
printx
A.4
B.5
C.10
D.15
E.Anexceptionisthrown
73.Iftheusertypes'0'atthepromptwhatgetsprinted?(B)
defgetinput():
print"0:start"
print"1:stop"
print"2:reset"
x=raw_input("selection:")
tr
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 苏教版小学第十册语文全册教案
- 2024年新版一年级语文(配套教案)2我爱我们的祖国
- 中国4-甲氧基-2-甲基二苯胺市场发展动态与投资价值分析报告2024-2030年
- 2024年角钢塔相关行业营销方案
- 2024年内衣行业营销策略方案
- 附属工程施工方案
- 广州市中考卷物理03年
- 2024年汽车底盘相关公司行业营销方案
- 2024年化药制剂相关行业营销方案
- 2024年离子风棒相关行业营销方案
- 手术室医院感染管理与质量持续改进课件
- 2022年旅游服务企业组织架构及部门职责
- JTJ312-2003 航道整治工程技术规范
- 《初中英语课程标准》解读之写作教学
- 股东退股竞业禁止协议
- 2024年《宪法》知识竞赛试题库及答案(共88题)
- 数学史概论第01讲-绪论
- 【课件】笔形与架构-表达文字内涵+课件高中美术人教版(2019)选择性必修4+设计
- 中国水溶性肥料发展现状调查报告
- 履行“一岗双责”情况报告
- 一年级数学100以内100道加减法口算题
评论
0/150
提交评论