PYTHON测试题_第1页
PYTHON测试题_第2页
PYTHON测试题_第3页
PYTHON测试题_第4页
PYTHON测试题_第5页
已阅读5页,还剩18页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、I.what does the following code do?(B)def a(b, c, d): passA.defines a list and initializes itB.defi nes a fun cti on, which does nothingC.defi nes a fun cti on, which passes its parameters throughD.defi nes an empty class2.what gets prin ted? Assu ming pyth on vers ion 2.xA) print type(1/2)A.vtype in

2、tB.vtype nu mberC.vtype floatD.vtype doubleE.vtype tuple3 what is the output of the following code?(E)print type(1,2)A.type tupleB.C.type setD.E.4.what gets prin ted? (C)def f(): pass print type(f()A.type functionB.C.type No neTypeD.E.5._what_should_the_below_code_pri nt?A) print type(1J)A.B.C.D.E.6

3、.what is the output of the following code?(D) print type(lambda:N one)A.vtype Non eTypeB.vtype tupleC.vtype typeD.type functionE.vtype bool7. what is the output of the below program?。)a = 1,2,3,No ne,(),print len(a)A.s yn tax errorB.4C.5D.6E.78.what gets prin ted? Assu ming pyth on vers ion 3.xC) pr

4、int (type(1/2)A.B.type nu mberC.type floatD.E.9. What gets prin ted?C)d=lambda p: p * 2t = lambda p: p * 3x : =2x : =d(x)x : =t(x)x : =d(x)pr nt xA.7B.12C.24D.36E.4810.What gets prin ted?A) x = 4.5y = 2 print x/yA.2.0B.2.25C.9.0D.20.25E.2111.What gets prin ted?C) nums = set(1,1,2,3,3,3,4) print len(

5、nu ms)A.1B.2C.4D.5E.712.What gets prin ted?A) x = Truey = False z = Falseif x or y and z:prin t yeselse:print noA.yesB.noC.fails to compile13.What gets prin ted?C) x = Truey = False z = Falseif not x or y:print 1elif not x or not y and z: print 2elif not x or y or not y and x: print 3else:print 4A.1

6、B.2C.3D.414.If PYTHONPATH is set in the environment, which directories are searchedfor modules?(D)A)PYTHONPATH directoryB)current directoryC)home directoryD)in stallati on depe ndent default pathA.A onlyB.A and DC.A, B, and CD.A, B, and DE.A, B, C, and D15.In python 2.6 or earlier, the code will pri

7、nt error type 1 if accessSecureSystem raises an excepti onof either AccessError type or SecurityError type() try:accessSecureSystem()except AccessError, SecurityError:prin t error type 1con ti nu eWork()A.trueB.false16.The following code will successfully print the days and then the monthsB) daysOfW

8、eek = Monday,Tuesday,Wed nesday, Thursday, Friday, Saturday, Su ndayJa n, Feb, Mar, Apr, May, Ju n, Jul, Aug, Sep, Oct, Nov, Decprin t DAYS: %s, MONTHS %s % (daysOfWeek, mon ths)A.trueB.false17.Assu ming pyth on 2.6 what gets prin ted?A) f = Nonefor i in range (5):with ope n(data.txt, w) as f: if i

9、2:breakprint f.closedmon ths =A.TrueB.FalseC.N one18.What gets prin ted?C) coun ter = 1def doLotsOfStuff(): global coun ter for i in (1,2, 3):coun ter += 1doLotsOfStuff()print coun terA.1B.3C.4D.7E.none of the above19.What gets prin ted?C) print rn woowA.new line then the string: woowB.the text exac

10、tly like this: rn woowC.the text like exactly like this: n woowD.the letter r and then newline then the text: woowE.the letter r then the text like this: nwoow20.What gets prin ted?B) prin t hello worldA.on one line the text: hello worldB.on one line the text: helloworldC.hello on one line and world

11、 on the n ext lineD.syntax error, this python program will not run21.What gets prin ted?E) prin t x48x49!A.x48x49!B.4849C.4849!D.4849!E.HI!22.What gets prin ted?D) prin t 0 xA + OxaA.OxA + 0 xaB.OxA 0 xaC.14D.20E.0 x2023.What gets prin ted?E) class pare nt:def _init_(self, param): self.v1 = paramcla

12、ss child(pare nt):def _init_(self, param): self.v2 = paramobj = child(11)prin t %d %d % (obj.vl, obj.v2)A.No ne NoneB.N one 11C.11 NoneD.11 11E.Error is gen erated by program24.What gets prin ted?E) kvps = user,bill, password,hillaryprint kvpspasswordA.userB.billC.passwordD.hillaryE.Nothi ng. Pyth o

13、n syn tax error25.What gets prin ted?B)66% on 1871 times askedclassAccount:def _init_(self, id): self.id = id id = 66649!acc = Accou nt(123) print acc.idA.No neB.123C.666D.SyntaxError, this program will not run26.What gets prin ted?C) n ame = snow storm prin t %s % name6:8A.stB.stoC.toD.torE.S yn ta

14、x Error27.What gets prin ted?D) n ame = snow stormname5 = Xprint n ameA.s now stormB.sno wXstormC.s now XtormD.ERROR, this code will n ot ru n28.Which numbers are prin ted?C)for i inran ge(2):print ifor i in ran ge(4,6): print iA.2, 4, 6B.O, 1,2, 4, 5, 6C.O, 1,4, 5D.0, 1,4, 5, 6, 7, 8, 9E.1,2, 4, 5,

15、 649!29.What seque nee of nu mbers is prin ted values = 1,2, 1,3 nums = set(values)def eheekit (nu m):if num in nu ms:return Trueelse:return Falsefor i in filter(eheekit, values):print iA.1 2 3B.1 2 1 3C.1 2 1 3 1 2 1 3D.1 1 1 1 2 2 3 3E.S yn tax Error30.What seque nee of nu mbers is prin ted?E) val

16、ues = 2, 3, 2, 4def my_tra nsformatio n(nu m):return num * 2for i inmap(my_tra nsformatio n, values):print iA.2 3 2 4B.4 6 4 8C.1 1.5 1 2D.1 1 1 2E.4 9 4 1631.What numbers get pri ntedC) import pickleclass acco unt:def _init_(self, id, bala nee): self.id = idself.bala nee = bala nee def deposit(self

17、, amoun t):self.bala nee += amount def withdraw(self, amoun t): self.bala nee -= amountmyac = accou nt(123, 100) myac.deposit(800) myac.withdraw(500)fd = ope n( archive, w) pickle.dump( myac, fd) fd.close()49!myac.deposit(200) print myac.bala neefd = ope n( archive, r) myac = pickle .lo ad( fd ) fd.

18、close()print myac.bala neeA.500 300B.500 500C.600 400D.600 600E.300 50032.What gets prin ted by the code sni ppet below?B) import mathprint math.floor(5.5)A.5B.5.0C.5.5D.6E.6.033.What gets printed by the code below?() class Pers on:def _init_(self, id): self.id = idobama = Perso n(100)obama._dict_ag

19、e = 49print obama.age + len (obama.dict)A.1B.2C.49D.50E.5134.What gets prin ted?E) x = foo y = 2 print x + yA.foo49!B.foo fooC.foo 2D.2E.A n excepti on is throw n35.What gets prin ted?E) def simpleF unction():This is a cool simple function that returns 1 return 1print simpleF unction. doc 10:14A.sim

20、pleF un ctio nB.simpleC.fu ncD.fun ti onE.cool36.What does the code below do?C) sys.path.appe nd(/root/mods)A.Cha nges the locati on that the pyth on executable is run fromB.Cha nges the curre nt worki ng directoryC.Adds a new directory to seach for pytho n modules that are importedD.Removes all dir

21、ectories for modsE.Cha nges the locati on where sub-processes are searched for after they are laun ched37.What gets prin ted?C) import resum = 0 pattern = backif re.match(pattern, backup.txt):sum += 1if re.match(pattern, text.back):sum += 2if re.search(pattern, backup.txt):sum += 4if re.search(patte

22、rn, text.back):sum += 8print sumA.3B.749!C.13D.14E.1538.Which of the following print statements will print all the names in the list on a seperate lin eA) names = Ramesh, Rajesh, Roger, Iva n, NicoA.pri nt n.jo in(n ames)B.pri nt n ames.jo in (n)C.pri nt n ames.c on cate nate(n)D.pri nt n ames.appe

23、nd(n)E.pri nt n ames.jo in (%sn, n ames)39.True or false? Code inden tati on must be 4 spaces whe n creat ing a code blocB?( if error:# four spaces of indent are used to create the block prin t %s % msgA.TrueB.False40.Assu ming the file name for the code below is /usr/lib/pytho n/pers on .py and the

24、 program is runas:pytho n /usr/lib/pyth on/pers on .pyWhat gets prin ted?D) class Pers on:def _init_(self): passdef getAge(self): print _n amep = Pers on() p.getAge()A.Pers onB.getAgeC.usr.lib.pytho n.pers onD._main_E.A n excepti on is throw n41.What gets prin tedB) foo = print type(foo)A.setB.dictC

25、.list49!D.tupleE.object42.What gets prin ted?C) foo = (3, 4, 5) print type(foo)A.i ntB.listC.tupleD.dictE.set43.What gets prin ted?D) coun try_co un ter = def add on e(co un try):if country in coun try_c oun ter:coun try_co un terco un try += 1else:coun try_co un terco un try = 1add on e(Chi na)add

26、on e(Japa n)add on e(chi na)print len(coun try c oun ter)A.0B.1C.2D.3E.444.What gets prin ted?D) con fusi on = con fusi on1 = 1con fusio n1 = 2con fusi on1 += 1sum = 0for k in con fusi on:sum += con fusi onk49!print sumA.1B.2C.3D.4E.545.What gets prin ted?C) con fusi on = con fusi on1 = 1con fusio n

27、1 = 2con fusio n1.0 = 4sum = 0for k in con fusi on:sum += con fusi onkprint sumA.2B.4C.6D.7E.A n excepti on is throw n46.What gets prin ted?E) boxes = jars = crates = boxescereal = 1 boxesca ndy = 2 jarsho ney = 4 cratesboxes = boxes cratesjars = jarsprint len( cratesboxes)A.1B.2C.4D.7E.A n excepti

28、on is throw n47. What gets prin ted?E)nu mberGames = 49!nu mberGames(1,2,4)=8numberGames(4,2,1)=10numberGames(1,2)=12sum = 0for k in nu mberGames:sum += nu mberGameskprint len(nu mberGames) + sumA.8B.12C.24D.30E.3348.What gets prin ted?A) foo = 1:1, 2:2, 3:3 foo = print len(foo)A.0B.1C.2D.3E.An exce

29、ption is thrown49.What gets prin ted?B) foo = 1:1, 2:2, 3:3 del foo1 foo1 = 10del foo2 print len(foo)A.1B.2C.3D.4E.A n excepti on is throw n50.What gets prin ted?E) names = Amir, Barry, Chales, Dao print n ames-1-1A.AB.rC.AmirD.DaoE.o49!51.What gets prin ted?B) names1 = Amir, Barry, Chales, Dao n am

30、es2 = n ames1n ames3 = n ames1:names20 = Alicenames31 = Bobsum = 0for ls in (n ames1, n ames2, n ames3): if ls0 = Alice:sum += 1if ls1 = Bob:sum += 10print sumA.11B.12C.21D.22E.3352.What gets prin ted?E) n ames1 = Amir, Barry, Chales, Dao loc = n amesl.i ndex(Edward)print locA.-1B.OC.4D.EdwardE.An e

31、xception is thrown53.What gets prin ted?B) names1 = Amir, Barry, Chales, Dao if amir in n ames1:print 1else:print 2A.1B.2C.A n excepti on is throw n54.What gets prin ted?C) names1 = Amir, Barry, Chales, Dao n ames2 = n ame .lo wer() for n49!ame in n ames1print n ames220A.iB.aC.cD.CE.An exception is

32、thrown55.What gets prin ted?B) numbers = 1,2, 3, 4nu mbers.appe nd(5,6,7,8)print len(nu mbers)A.4B.5C.8D.12E.A n excepti on is throw n56.Which of the following data structures can be used with the in operator to check if an item is inthe data structure?E)A.listB.setC.dictio naryD.None of the aboveE.

33、AII of the above57.Wat gets prin ted?D) list1 = 1,2, 3, 4 list2 = 5, 6, 7, 8print len( listl + Iist2)A.2B.4C.5D.8E.A n excepti on is throw n58.What gets prin ted?C)49!def addltem(listParam): listParam += 1mylist = 1,2, 3, 4 addltem(mylist) print len(m ylist)A.1B.4C.5D.8E.A n excepti on is throw n59.

34、What gets prin ted?E) my_tuple = (1,2, 3, 4) my_tuple.appe nd( (5, 6, 7) print len(m y tuple)A.1B.2C.5D.7E.An exception is thrown60.What gets prin ted?B) a = 1b = 2a,b = b,aprin t %d %d % (a,b)A.1 2B.2 1C.A n excepti on is throw nD.This program has un defi ned behavior61.What gets prin ted?A)def pri

35、n t_header(str): prin t +%s+ % strprin t_header.category = 1prin t_header.text = some infoprint_header(%d %s % (print header.category, print header.text)49!A.+1 some in fo+B.+%s+C.1D.some info62.What gets prin ted?C) def dostuff(param1, *param2):print type(param2)dostuff(apples, ba nan as, cherry, d

36、ates)A.strB.i ntC.tupleD.listE.dict63.What gets prin ted?( E)def dostuff(param1, *param2): print type(param2)dostuff(capitals, Ariz on a=Phoe ni x, Califor ni a=Sacrame nto, Texas=Aust in)A.inB.strC.tupleD.listE.dict64.What gets prin ted?B)def myfun c(x, y, z, a): print x + ynums = 1,2, 3, 4myfun c(

37、* nu ms)A.1B.3C.649!D.10E.A n excepti on is throw n65.How do you create a package so that the follow ing refere nee will work?C) p =mytools.myparser.MyParser()A.Declare the myparser package in mytools.pyB.Create an _init_.py in the home dirC.ln side the mytools dir create a _init_.pyD.Create a mypar

38、ser.py directory in side the mytools directoryE.This can not be done66.What gets prin ted?E) class A:def _init_(self, a, b, c): self.x = a + b + ca = A(1,2,3) b = getattr(a, x) setattr(a, x, b+1) print a.xA.1B.2C.3D.6E.767.What gets prin ted?E) class NumFactory: def _init_(self, n): self.val = n def timesTwo(self): self.val*= 2 def plusTwo(self): self.val += 2 f = NumFactory(2) for m in dir(f):mthd = getattr(f,m) if callable(mthd): mthd()print f.valA.2B.4C.6D. 8E.A n excepti on is throw n68.What gets prin ted?A)

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论