PYTHON測試題經(jīng)典.doc_第1頁
PYTHON測試題經(jīng)典.doc_第2頁
PYTHON測試題經(jīng)典.doc_第3頁
PYTHON測試題經(jīng)典.doc_第4頁
PYTHON測試題經(jīng)典.doc_第5頁
已閱讀5頁,還剩16頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、l.what does the following code do? (B) def a(b, c, d): passA.defines a list and initializes itB.defines a function, which does nothingC.defines a function, which passes its parameters through D.defines an empty class2. what gets printed? Assuming python version 2.x(A) print type(l/2)A.<type '

2、int'>B.<type 'number'C.<type 'float'D.<type 'double'E.<type 'tuple'3. what is the output of the following code? (E) print type" 1,2)A.<type 'tuple'B.<type 'int'>C.<type 'set'D.<type 'complex' E.<

3、;type 'list'4. what gets printed? (C) def f(): pass print type(f()A.<type 'function'B.<type 'tuple'C.<type 'NoneType'D.<type *stf>E.<type 'type'5. what should the below code print?(A) print type(U)A.<type 'complex'B.<type 'u

4、nicode'C.<type 'int'>D.<type 'float'E.<type 'diet'6. what is the output of the following code?(D) print type(lambda:None)A.<type 'NoneType'B.<type 'tuple'C.<type 'type'D.<type 'function'E.<type *boor>7. what is

5、 the output of the below program?(D) a= 1,2,3,None,(), print len(a)A.syntax errorB.4C.5D.6E.78. what gets printed? Assuming python version 3.x(C) print (type(l/2)A.<typeB.<type 'number'C.<type 'float' D.<type 'double' E.<type 'tuple'9. What gets printed

6、?(C) d = lambda p: p * 2t = lambda p: p * 3x = 2x = d(x)x = t(x)x = d(x) print xA.7B.12C.24D.36E.4810. What gets printed?(A) x = 4.5y = 2print x/yA.2.0B.2.25C.9.0 D.20.25E.2111. What gets printed?(C) nums = set( 1,1,2,3,3,3,4) print len(nums)A.lB.2C.4D.5E.712. What gets printed?(A) x = Truey = False

7、z = Falseif x or y and z:print HyesHelse:print HnoMA.yesB.noC.fails to compile13. What gets printed?(C) x = Truey = Falsez = 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.lB.2C.3D.414. If PYTHONPATH is set in the environment, which di

8、rectories are searched for modules?(D)A) PYTHONPATH directoryB) current directoryC) home directoryD) installation dependent 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 print error type 1 if accessSecureSystem raises an exception

9、of either AccessError type or SecurityError type(B) try:accessSecureSystem()except AccessError, SecurityError: print Merror type 1 ”continueWork()A.trueB.false16. The following code will successfully print the days and then the months(B) daysOfWeek = 'Monday',Tuesday','Wednesday, 

10、9;Thursday', 'Friday', 'Saturday', 'Sunday'months ='Jan; 'Feb', Mar', 'Apr: 'May; 'Jun', 'Jul', ,Aug; Sep', 'Oct; 'Nov; 'Dec'print HDAYS: %s, MONTHS %sH % (daysOfWeek, months)A.trueB.false17. Assuming python 2.6

11、what gets printed?(A) f = Nonefor i in range (5):with open(Hdata.txtH, nwM) as f: ifi>2:breakprint f.closedA.TrueB.FalseC.None18. What gets printed?(C) counter = 1def doLotsOfStuff():global counterfor i in (1, 2, 3): counter += 1doLotsOfStuff()print counterA.lB.3C.4D.7E.none of the above19. What

12、gets printed?(C) print rnnwoowMA.new line then the string: woowB.the text exactly like this: BXnwoow”C.the text like exactly like this: nwoowD.the letter r and then newline then the text: woowE.the letter r then the text like this: nwoow20. What gets printed?(B) print "hello" 'world

13、9;A.on one line the text: hello worldB.on one line the text: helloworldC.hello on one line and world on the next lineD.syntax error, this python program will not run21. What gets printed?(E) print "x48x49!”A.x48x49!B.4849C.48491D. 4849!E.HI!22. What gets printed?(D) print OxA + OxaA.OxA + OxaB.

14、OxAOxaC.14D.2OE.0x2023. What gets printed?(E) class parent:definit_(self, param): self.vl = paramclass child(parent):definit_(self, param):self.v2 = paramobj = child(ll)print n%d %dH % (obj.vl, obj.v2)A.None NoneB.None 11C.l 1 NoneD.ll 11E.Error is generated by program24. What gets printed?(E) kvps

15、= "user"/'biir; HpasswordH;,hillaryn)print kvps'password'A.userB.billC. pass wordD.hillaryE.Nothing. Python syntax error25. What gets printed?(B)66% on 1871 times askedclass Account:definit_(self, id): self.id = id id = 666acc = Account(123)print acc.idA.NoneB.123C.666D.SyntaxE

16、rror, this program will not run26. What gets printed?(C) name = "snow stormHprint "%s" % name6:8A.stB.stoC.toD.torE.Syntax Error27. What gets printed?(D) name = "snow stormHname5 ='X'print nameA.snow stormB.snowXstormC.snow XtormD.ERROR, this code will not run28. Which nu

17、mbers are printed?(C)for i in range(2): print ifor i in range(4,6): print iA2 4, 6B.O, 1,2,4,5,6C.O, 1,4,5D.O, 1,4,5, 6, 7, 8,9E.l,2, 4, 5,629. What sequence of numbers is printed?(B) values = 1,2, 1, 3 nums = set(values)def checkit(num):if num in nums:return Trueelse:return Falsefor i in filter(che

18、ckit, values): print iA.l 23B.l 2 1 3C.l 2 1 3 1 2 1 3D.l 1 1 1 223 3E.Syntax Error30. What sequence of numbers is printed?(E) values = 2, 3, 2, 4def my_transformation(num):return num * 2for i in map(my_transformation, values): print iA.2 3 24B.4 6 4 8C.l 1.5 1 2D.l 1 1 2E.4 9 4 1631. What numbers g

19、et printed(C) import pickleclass account:definit_(self, id, balance): self.id = idself.balance = balancedef deposit(self, amount): self.balance += amountdef withdraw(self, amount): self.balance -= amountmyac = account(1123 100)myac.deposit(800)myac.withdraw(500)fd = open( "archive", "

20、w") pickle.dump( myac, fd)fd.close()niyac.deposit(200)print myac.balancefd = open( "archive", ) myac = pickle.load( fd )fd.close()print myac.balanceA.500 300B.500 500C.600 400D.600 600E.300 50032. What gets printed by the code snippet below?(B) import mathprint math.floor(5.5)A.5B.5.0

21、C.5.5D.6E.6.033. What gets printed by the code below?(E) class Person:definit_(self, id): self.id = idobama = Person(lOO)obama.dietage' = 49print obama.age + len(obama.diet)A.lB.2C.49D.50E.5134. What gets printed?(E) x = Hfoo " y = 2 print x + yA.fooB.foo fooC.foo 2D.2E.An exception is thro

22、wn35. What gets printed?(E) def simpleFunction():“This is a cool simple function that returns 1 return 1print sinipIeFunction.doc10:14A.simpleFunctionB.simpleC.funcD.funtionE.cool36. What does the code below do?(C) sys.path.append(7root/mods')A.Changes the location that the python executable is

23、run fromB.Changes the current working directoryC.Adds a new directory to seach for python modules that are importedD.Removes all directories for modsE.Changes the location where sub-processes are searched for after they are launched37. What gets printed?(C) import resum = 0pattern = 'back'if

24、 re.match(pattern, 'backup.txtr): sum += 1if re.match(pattern, ext.back1): sum += 2if re.search(pattern, 'backup.txt1): sum += 4if re.search(pattern, *text.backr): sum += 8print sumA.3B.7C.13D.14E.1538. Which of the following print statements will print all the names in the list on a seperat

25、e line(A) names =Ramesh', 'Rajesh', 'Roger: 'Ivan', Nico'A.print HnH.join(names)B.print names.join(HnM)C.print names.concatenate(HnM)D.print names.append(HnM)E.print names.join(H%sn, names)39. True or false? Code indentation must be 4 spaces when creating a code block?(B)

26、 if error:# four spaces of indent are used to create the block print n%sH % msgA.TrueB.False40. Assuming the filename for the code below is /usr/lib/python/person.py and the program is run as:python /u sr/1 i b/py t hon/person. pyWhat gets printed?(D)class Person:definit_(self):passdef getAge(self):

27、 print _namep = Person()p.getAge。A.PersonB.get AgeC.usr.lib.python.pereonD.main-E.An exception is thrown41. What gets printed(B)foo = ) print type(foo)A.setB.dictC.Iist D.tuple E.object42. What gets printed?(C) foo = (3, 4, 5) print type(foo)A.intB.listC.tupleD.dictE.set43. What gets printed?(D) cou

28、ntry_cou nter = )def addone(country):if country in country_counter:country_cou nter country += 1 else:country_cou nter country = 1addoneCChina*) addone('Japan') addone('china')print len(country counter)A.OB.lC.2D.3E.444. What gets printed?(D) confusion = confusionl = 1confusionT = 2c

29、onfusionfl += 1sum = 0for k in confusion:sum += confusionkprint sumA.lB.2C.3D.4E.545. What gets printed?(C) confusion = ) confusionfl = 1 confusionT = 2 confusionfl.O = 4sum = 0for k in confusion:sum += confusionkprint sumA.2B.4C.6D.7E.An exception is thrown46. What gets printed?(E) boxes = jars = )

30、 crates = )boxestereaF = 1boxes'candy1 = 2 jarshoney' = 4 crates'boxes* = boxes cratesljars1 = jarsprint len(cratesboxes)A.lB.2C.4D.7E.An exception is thrown47. What gets printed?(E) numberGames = ) numberGames( 1,2,4) = 8 numberGames(4,2,1) = 10 numbei<ianies( 1,2) = 12sum = 0for k i

31、n numberGames:sum += numberGameskprint len(numberGames) + sumA.8B.12C.24D.30E.3348. What gets printed?(A) foo= 1:T,2:'2',3:3 foo = ) print len(foo)A.OB.lC.2D.3E.An exception is thrown49. What gets printed?(B) foo= 1:T,2:'2',3:3 del foo 1 fool = ,10, del foo2 print len(foo)A.lB.2C.3D.

32、4E.An exception is thrown50. What gets printed?(E) names =Amir', 'Barry'JChales; 'Dao' print names-l-lA.AB.rC.AmirD.DaoE.o51. What gets printed?(B) names 1 =Amir', 'Barry'JChales'JDao' names2 = names 1names3 = names 1:names20 = 'Alice'names3l = 'Bo

33、b'sum = 0for Is in (names L names2, names3):if ls0 = 'Alice': sum += 1if Isl='Bob': sum += 10print sumA.llB.12C.21D.22E.3352. What gets printed?(E)|names 1 = *Amir arry1, *Chales ao* loc = names 1 .index(HEd ward*) print locA.-lB.OC.4D.EdwardE.An exception is thrown53. What gets

34、printed?(B) names 1 =Amir', 'Barry', Chales', 'Dao'if amir in names 1:print 1else:print 2A.lB.2C.An exception is thrown54. What gets printed?(C)names 1 = 'Amir; 'Barry', Chales', 'Dao' names2 = name.lower() for name in names 1 print names220A.iB.aC.cD.

35、CE.An exception is thrown55. What gets printed?(B) numbers = 1,2, 3, 4numbers.append(5,6,7,8)print len(numbers)A.4B.5C.8D.12E.An exception is thrown56. Which of the following data structures can be used with the ''in” operator to check if an item is in the data structure?(E)A.listB.setC.dict

36、ionaryD.None of the aboveE.A11 of the above57. Wat gets printed?(D) listl = 1,2, 3,4 list2 = 5, 6, 7, 8print Ien(listl + Iist2)A.2B.4C.5D.8E.An exception is thrown58. What gets printed?(C)def addltem(listParam): listParam += 1mylist = 1, 2, 3, 4 addltem(mylist) print len(mylist)A.lB.4C.5D.8E.An exce

37、ption is thrown59. What gets printed?(E) my_tuple = (l,2, 3,4) my_tuple.append( (5, 6, 7) print len(my tuple)A.lB.2C.5D.7E.An exception is thrown60. What gets printed?(B) a = 1b = 2a,b = b,aprint n%d %dH % (a,b)A.l 2B.2 1C.An exception is thrownD.This program has undefined behavior61. What gets prin

38、ted?(A)def print_header(str): print n+%s+H % strprint_header.category = 1 print_header.text = "some info”print_header("%d %s" % (printJieader.category, printjieader.text)A.+1 some info+B.+%s+C.lD.some info62. What gets printed?(C)I def dostuff(paraml, *param2):print type(param2)dostuf

39、f('apples','bananas', 'cherry', 'dates')A.strB.intC.tupleD.listE.dict63. What gets printed? (E) def dostuff(paraml, *param2):print type(param2)dostuff(capitals Arizona=fPhoenixCalifornia=,Sacramento Texas=Austin1)A.inB.strC.tupleD.listE.dict64. What gets printed?(B)de

40、f myfunc(x, y, z, a): print x + ynums = 1, 2, 3, 4myfunc(*nums)A.lB.3C.6D.10E.An exception is thrown65. How do you create a package so that the following reference will work?(C) p = my tool s. my parser. M y Parser()A.Declare the myparser package in mytools.pyB.Create an _init.py in the home dirC.In

41、side the mytools dir create a _init.pyD.Create a myparser.py directory inside the mytools directoryE.This can not be done66. What gets printed?(E) class A:definit_(self, a, b, c): self.x = a + b + ca = A(l,2,3) b = getattr(a, *x*) setattr(a, b+1) print a.xA.lB.2C.3D.6E.767. What gets printed?(E) cla

42、ss NumFactory: definit_(self, n): self.val = ndef timesTwo(self) self.val *= 2 def pkisTwo(self): self.val += 2f = NumFactory(2)for m in dir(f):mthd = getattr(fm) if callable(mthd): mthd()print f.valA.2B.4C.6D.8E.An exception is thrown68. What gets printed?(A) one = chr(104)two = chr(105)print n%s%s

43、H % (one, two)A.hiB.hC.Inside the mytools dir create a _init.py and myparser.pyD.104105E.10469. What gets printed?(A) x = 0 y=1 a = cmp(x,y) if a < x:print "a" elif a = x:print "b" else:print ncHA.aB.bC.c70. What gets printed?(C) x = 1y = n2"z = 3 sum = 0for i in (x,y,z):

44、if isinstance(i, int): sum += iprint sumA.2B.3C.4D.6E.An exception is thrown71. What gets printed (with python version 2.X) assuming the user enters the following at the prompt?(D)#: foo a = input。'#:")print aA.fB.fooC.#: fooD.An exception is thrown72. What gets printed?(C) x = sum(range(5) print xA.4B.5C.10D.15E.An exception is thrown73. If the user types *0* at the prompt what gets printed?(B) def getinput()

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論