PYTHON测试题.doc

上传人:大张伟 文档编号:8571116 上传时间:2020-11-26 格式:DOC 页数:41 大小:72.50KB
返回 下载 相关 举报
PYTHON测试题.doc_第1页
第1页 / 共41页
PYTHON测试题.doc_第2页
第2页 / 共41页
PYTHON测试题.doc_第3页
第3页 / 共41页
亲,该文档总共41页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《PYTHON测试题.doc》由会员分享,可在线阅读,更多相关《PYTHON测试题.doc(41页珍藏版)》请在三一文库上搜索。

1、PYTHON测试题1.t doe the foling coe do?()def (b, c, ): pas.deines a lis and nilzes itB.defe a function, hc deoigC.eins afuncion, whc pass itparamers rughdeines an mty cls.wa es prnt? ssuming ython vrsion 2.x(A)print type(1/)A.Bty nmbeC.D.3wa te output of e oloin cd?(E)prin tpe(1,)A.e inCD.E.4. what gets

2、 rintd?()def f(): assprin typ(f())AB.type tupC.D.E. washou thebelw code print?(A)in ype(1J)A.B.tyeuncodetye tD.tye flot.6. watis th outputof the followin cod?(D)inttpe(lambd:None)AD.tye funtinypeool7. whatisth outpt the below progam?()= 1,2,3,one,(),rint ln(a)A.synax rrorB4C.5DE.78.wt gsprintd? Assu

3、ming pythoverion .x(C)prt (typ(12)A.D.E. 2: eakprin .cos.TrueB.FalseC.Noe18.Whtet pnte?()ontr = def doLotsOfStuff(): global cunte for i (1, 2, ): couner+=1dofSuf()pint ouer.B.CD.7E.one of the above19. What gts prnt?(C)rin roowA.n ie hen hstrin: oow.te tet ectlylike th: rnwoowC.t tet like xactlylik h

4、is: wo.te ltter and tenwn enth text:wowE.te letr r ten the txtlethi: noow20.Wagetspintd?(B)print helloworldAon ne lne hetext: hlo world.on elnte text:helwordC.llo none lne and world onthe tlineD.ynt errr,ispythn ogramwillnot run21Waets prin?(E)printx849!x48x9!B.4849.84!D. 4 49!E.I!2. What gets rinte

5、d?(D)prnt A + 0A0xA + 0xaBx0xaC.4D.20.x023. Wha getsprinte?(E)cass aren: e _ini_(self, ara): self. =paamclas hl(parent): df_iit_(sel, pram): sl2 paramobj = chi(1)pint%d %d %(obj.1, ojv2)ANone NonB.ne1. Nne.11 1EEror is gerated bypogam24 Wa getspred?(E)kvp = use,ill, assord,hilaryprint kvpsssord.user

6、.bllC.pswor.hillarE.NothingPytonsyna erro2. Wat epind?()6% o 87 times skdclas Acount: def _init_(self,id): sel.i =id i= 6 acc = Acount(13)rit c.idA.NoneB.123.666DSyntaxError, tis ra ill ot run2 What gts printe?(C)nme snow strmprint% % nm6:8A.sB.stoC.to.toESyax Error27.Wh ets pried?()name =sowomnme X

7、in meA.w somB.snowXstorCsnoXormD.ERRR, i code illno un28. Whih numberreprinted?(C)or in rnge(2): print or i in ange(4,): prntA.2,4, 6B0, 1,2, 4, 5, 6C, 1, , 5D.0, 1, 4, 5, 6, 7, ,9.1, 2, , 5, 629. Wh euence of nuberis printd?(B)s = 1, 2,ms=set(valus)def checkit(num): if nmi nums: rtn r else: retunFl

8、sfo i in fiter(cekt,alues): rt iA.1 2 3B.1 1 C.1 1 311 3.1 1 12 3 3E.Syntaxrror30. Wt seunce of numbess prited?()vale = 2, 3, 2,4ef my_tasorati(num): return nu * 2foi in a(m_rasfomatio, vlues): printi 3 4B4 6 41 1.5 1 D.1 1 1 24 94 1631. What nmbers get printed()mport pickleclas count:f _nit_(elf,i,

9、 balance):sfd =idself.balance= balncef epi(s, out):self.aace+= mountde wtdraw(sf, aoun):slfbalnce -mutmyac ccount(123, 10)mac.dos(80)myahraw(5)fd open(rcive, ) pikle.du(mac,)fdcoe()mycdposit(00)rint yac.alaned=opn( arche, r) myac= ikl.load(fd)fd.cloe()print mycalceA.500 3B.500500C.00 400D600 60E.00

10、50032 ha ge prite byth o snieteow?()iprt hrinathfloo(.5).B.5.0C5D6.03 What et rnted by thece lw?(E)clas Person: de_t_(self, id): self.id = iobama = Pern(100)obama._dict_ =49pit oba.age + ln(obama._dct_)AB2C9D.5E.5134. Wt et prid?(E)x foy = 2prin x yAfo.f fo.foo D.2E.n exceptis ro3. Wh gets rinted?()

11、df smpeuctio(): This s a coo imple fun that returns 1 retur 1print sipeFuntin_do_10:14.sipentonB.simple.funcDfnion.cool36.Wat oes the code lo do?(C)syspathapnd(/roo/mods)AChange te ocation that t ptho xecutableisrun rm.agehe uentwking direcryC.Ad a new directrtsach for ython mdules ateimpotDRemoes l

12、 dctores formodEChges theocaionwhereuprceseseserchdfoaferey e lauced37.Whatesprinted?(C)t eum= pate = bakif re.match(pattern, backup.txt): sum= 1ifre.match(pttrn, xbk): sm + 2if r.sch(pater, bacuptxt): sum += 4ie.seah(patern, tet.back): sum+= 8pintsumA.3B.7C.13D.14E158 h ftefollowinprin stemnts llpr

13、nt lthe mes in theli ona seaelne(A)ames = Rash,Rajs, Roer, an, NicA.pnjoin(names)B.print nams.joi(n)Cprin names.concatenate()Dprint nas.pend(n)E.in namesjoi(%sn, name)3. Tru orflse? Ceaton ms be4 pes when creanacode bloc?(B)if rrr: # our spaceofndent are u o crate he block pn%s %ms.TueB.ase4. Assumi

14、ng h for thecod bew iusr/lib/pthonpero.ynd the pogrm is rna: python/usrlib/pthon/perso.py What getsprted?(D)classero: def _i_(self): ass def etAge(slf): print _name_p Peson()pgeA()A.PrsonBgetAgeCur.lb.pyhn.personD_ain_E.Anexetios tro4. Wh ets ined()fo = print te(foo)A.stBdictCstD.tule.jec4.What etsr

15、nted?(C)fo = (3, , 5)rint tpe(foo).intB.itC.tupleD.dictE.se3 ht gets pnte?(D)ury_outer = def addon(country): conty incountry_counter: contrycountercuntry += 1 el: uy_couecunty = 1doe(China)ao(Japn)addne(hina)intn(cotcontr)01.D.3.444 at getind?(D)onuson =cofusn1 = 1cofion1 = confuion1 1sm0 k in cfuso

16、: sum= nfsionrnt sumA.1B.D.4E545 Wht g pined?()confio = conusion1onfusion = onusion.0 = 4sum=0fo k iconuo: sum += cofusiint s.B.4C.D.7E.An xcepton i thrw4.Wht gtinted?(E)oes a cate = boxcea =1boxesand = 2jrsne =cratesbo boxescrateas = asprint len(atesbxes)AB.2C4D.7EAnexcption isthrwn7.at gets ried?(

17、E)ubeGams numrGames(1,,4) = 8nuerGams(4,2,1) = 10nbeGam(1,) =1u = for k in umberames: sum + numberGmeskpin en(numberam) sumA.8.2C.24D.30E.348. Wha gt prnted?(A)oo=1:1, :, 3:fo = rint en(foo).0B.C.2D.3E.Anexepin is trn9. hat gets rite?(B)fo 1:1, :2, 3:3el foooo 10del foo2prntlen(foo)A.1B2C.3D4E.An xc

18、eptonis thrown5 What e printd?(E)ns = Amir, Bar, Cha,aoin mes-1A.A.rC.AirD.DoE.51.hat gt n?(B)nmes1 = Ar, arry, Chale, Doams2 name1nmes3 = names1:nms0 Aicenms31 = osum 0for s n (ame1, mes, mes): i ls lie: sm=1 ifls1 = Bob: sum+= 10printmA11B.2C.21D2E332. What ets rinted?()aes = Amir, Bary,haes, Dolo

19、c = names1inde(dard)print lcA.-1.C4D.EdadE.An excetiois hrown5. t gtinted?(B)naes = mir, Barry, Chales, Doif amir n nmes1: rin 1else: print 1B.C.Aexcpon thro54. What etsrtd?(C)ames1= Amir,Barry, Caes, Daonmes2 = nam.lower()fo nae n namesprnt ames220Ai.aCcD.CE.A epion i thon55. Watgespried?(B)nber =1

20、, ,3, 4number.apen(5,6,7,8)print en(brs).45C.8.12En excptio i thron56. Wch of thefollongdata strurs cnbe used ith the in operator to eck if an itm s inthedastructu?(E)A.sBset.icionryD.Neof theaoe.l of thebve7. Wat gets prite?(D)list1 = 1, , , ls , , 7,print (lst+ list2)A.2B.4.D.8E.n excepn s thrwn58

21、. Wht getsprin?()def ddIem(listParam): istParam + 1ylist= ,2, 3, 4adItem(lst)println(myst)A.1B.4C.5D.8E.n eptioi hrown59 What gets pinted?(E)mytule = (1, 2,3, 4)my_tuple.append( (5, , 7) )prn en(y_tpe)A.1B.2C.5D7.An except s trown60hat gs pnte?()a 1b=2,b= b,prnt % d % (,b)A.1 B.2 1C.Aecpin i trnD.hi

22、s ogam as nefine behavio1 Wht gets prined?(A)efprit_header(tr): prin+%s+ % strrnt_hercategory = 1rntheae.et= some infoprin_eder(% % % (printheer.caeory, pnt_hear.))A+ some info+B.s+C1D.om info62.hat gets pnted?(C)de dtuff(aa1,*paam2): prt type(param2)tuf(appes,banas,chery,ts)A.stB.itCupleD.istE.dict

23、63. What espred?(E)efotuff(aram, *aram2): prnt te(param2)dsuff(als, rizn=oi,Californaacraento, Texs=Austn)A.inB.ple.istEdct4.Whagtinte?(B)de func(, y, , a): print x+ynm=1,2, 3, myfun(*s)A.B3.6D.10E.An exceptions thrown5.How do ou createa package so that the foloing refernc ll wk?(C)p =ytoolsmparsr.y

24、Paser()Aelrehe myar pckagin myols.B.at n _init_.y ihe homedCide h mytools dir eate a _iit_.pyD.Create a yprse.py dictr nside the mytoos irectoryE.Thiscan not b doe6.What gets printed?(E)class A: df _ini_(l,a,b,c): slf.x a bca = A(1,2,3)b = getatr(a, x)setat(,x, 1)pint a.xA.BC.3D6E.77. Wha gets pitd?

25、(E)clss NmFty: de _int_(self, n): self.val= n def timeTwo(sef): sll = 2 def plusTo(self): el.val + 2f = NuFacory(2)or m inir(f): m = geattr(,m) if callale(thd): mt()prt f.valA.2B.4C.6D.8An exceptioni hrown68.What ges rint?(A)one = hr(04)to=cr(105)print %s%s % (n, two)A.hiB.hC.nie the mytools dirte _

26、init_p a ypserpyD.104105E.1469. Wa et rited?()x=0y = 1a = cmp(x,)if a : pntaei = : it bels: print cA.aB.bC.c70 ha g rinted?(C)x =1y = 2z= 3sum=0for i in (x,y,z): issac(i,nt): sum += print umA.B.C.6E.Anxception s thrown71 ha gets rinte(wihythn veon 2.X) assing he uer eers he ollowingat thepromp?(D)#: foa =inp(:)prnt aA.B.foo.#:fooDAn excponithrown7 ht ge printed?(C)x um(ange(5))prntxA.4B.5C.10D.15EAn xceptio is thown73.If thuser ypes 0 at thepromptwht et pinted?()de tinut(): pint 0:strt print : sop p

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 科普知识


经营许可证编号:宁ICP备18001539号-1