1、PYTHON测试题1.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 throughD.defines an empty class2.what gets printed? Assuming python version 2.x(A)print type(1/2)A.B.C.D.E.3.
2、 what is the output of the following code?(E)print type(1,2)A.B.C.D.E.4. what gets printed?(C)def f(): passprint type(f()A.B.C.D.E.5. what should the below code print?(A)print type(1J) A.B.C.D.E.6. what is the output of the following code?(D)print type(lambda:None) A.B.C.D.E.7. what is the output of
3、 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(1/2) A.B.C.D.E.9. What gets printed?(C)d = lambda p: p * 2t = lambda p: p * 3x = 2x = d(x)x = t(x)x = d(x)print x A.7B.12C.24D.36E.4810. What gets printed?(A)
4、x = 4.5y = 2print x/y A.2.0B.2.25C.9.0D.20.25E.2111. What gets printed?(C)nums = set(1,1,2,3,3,3,4)print len(nums) A.1B.2C.4D.5E.712. What gets printed?(A)x = Truey = Falsez = Falseif x or y and z: print yeselse: print no A.yesB.noC.fails to compile13. What gets printed?(C)x = Truey = Falsez = False
5、if 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 4 A.1B.2C.3D.414. If PYTHONPATH is set in the environment, which directories are searched for modules?(D)A) PYTHONPATH directoryB) current directoryC) home directoryD) installation dependent de
6、fault path A.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 of either AccessError type or SecurityError type(B)try: accessSecureSystem()except AccessError, SecurityError: print error ty
7、pe 1continueWork() A.trueB.false16. The following code will successfully print the days and then the months(B)daysOfWeek = Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sundaymonths = Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Decprint DAYS: %s, MONTHS %s % (daysOfWeek, months)
8、 A.trueB.false17. Assuming python 2.6 what gets printed?(A)f = Nonefor i in range (5): with open(data.txt, w) as f: if i 2: breakprint f.closed A.TrueB.FalseC.None18. What gets printed?(C)counter = 1 def doLotsOfStuff(): global counter for i in (1, 2, 3): counter += 1doLotsOfStuff()print counter A.1
9、B.3C.4D.7E.none of the above19. What gets printed?(C)print rnwoow A.new line then the string: woowB.the text exactly like this: rnwoowC.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
10、hello world 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.4849!D. 48 49!E.HI!22. What gets printed?(D)print 0xA + 0xa A.0xA + 0x
11、aB.0xA 0xaC.14D.20E.0x2023. What gets printed?(E)class parent: def _init_(self, param): self.v1 = paramclass child(parent): def _init_(self, param): self.v2 = paramobj = child(11)print %d %d % (obj.v1, obj.v2) A.None NoneB.None 11C.11 NoneD.11 11E.Error is generated by program24. What gets printed?(
12、E)kvps = user,bill, password,hillaryprint kvpspassword A.userB.billC.passwordD.hillaryE.Nothing. Python syntax error25. What gets printed?(B)66% on 1871 times askedclass Account: def _init_(self, id): self.id = id id = 666 acc = Account(123)print acc.id A.NoneB.123C.666D.SyntaxError, this program wi
13、ll not run26. What gets printed?(C)name = snow stormprint %s % name6:8 A.stB.stoC.toD.torE.Syntax Error27. What gets printed?(D)name = snow stormname5 = Xprint name A.snow stormB.snowXstormC.snow XtormD.ERROR, this code will not run28. Which numbers are printed?(C)for i in range(2): print ifor i in
14、range(4,6): print i A.2, 4, 6B.0, 1, 2, 4, 5, 6C.0, 1, 4, 5D.0, 1, 4, 5, 6, 7, 8, 9E.1, 2, 4, 5, 629. What sequence of numbers is printed?(B)values = 1, 2, 1, 3nums = set(values)def checkit(num): if num in nums: return True else: return Falsefor i in filter(checkit, values): print i A.1 2 3B.1 2 1 3
15、C.1 2 1 3 1 2 1 3D.1 1 1 1 2 2 3 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 i A.2 3 2 4B.4 6 4 8C.1 1.5 1 2D.1 1 1 2E.4 9 4 1631. What numbers get printed(C)import pickleclass a
16、ccount: def _init_(self, id, balance): self.id = id self.balance = balance def deposit(self, amount): self.balance += amount def withdraw(self, amount): self.balance -= amountmyac = account(123, 100)myac.deposit(800)myac.withdraw(500)fd = open( archive, w ) pickle.dump( myac, fd)fd.close()myac.depos
17、it(200)print myac.balancefd = open( archive, r ) myac = pickle.load( fd )fd.close()print myac.balance A.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.0C.5.5D.6E.6.033. What gets printed by the code below?(E)class
18、 Person: def _init_(self, id): self.id = idobama = Person(100)obama._dict_age = 49print obama.age + len(obama._dict_) A.1B.2C.49D.50E.5134. What gets printed?(E)x = foo y = 2print x + y A.fooB.foo fooC.foo 2D.2E.An exception is thrown35. What gets printed?(E)def simpleFunction(): This is a cool simp
19、le function that returns 1 return 1print simpleFunction._doc_10:14A.simpleFunctionB.simpleC.funcD.funtionE.cool36. What does the code below do?(C)sys.path.append(/root/mods) A.Changes the location that the python executable is run fromB.Changes the current working directoryC.Adds a new directory to
20、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 = backif re.match(pattern, backup.txt): sum += 1if re.match(pattern, text.back): sum += 2if
21、re.search(pattern, backup.txt): sum += 4if re.search(pattern, text.back): sum += 8print sum A.3B.7C.13D.14E.1538. Which of the following print statements will print all the names in the list on a seperate line(A)names = Ramesh, Rajesh, Roger, Ivan, Nico A.print n.join(names)B.print names.join(n)C.pr
22、int names.concatenate(n)D.print names.append(n)E.print names.join(%sn, names)39. True or false? Code indentation must be 4 spaces when creating a code block?(B)if error: # four spaces of indent are used to create the block print %s % msg A.TrueB.False40. Assuming the filename for the code below is /
23、usr/lib/python/person.pyand the program is run as: python /usr/lib/python/person.py What gets printed?(D)class Person: def _init_(self): pass def getAge(self): print _name_p = Person()p.getAge() A.PersonB.getAgeC.usr.lib.python.personD._main_E.An exception is thrown41. What gets printed(B)foo = prin
24、t type(foo) A.setB.dictC.listD.tupleE.object42. What gets printed?(C)foo = (3, 4, 5)print type(foo) A.intB.listC.tupleD.dictE.set43. What gets printed?(D)country_counter = def addone(country): if country in country_counter: country_countercountry += 1 else: country_countercountry = 1addone(China)add
25、one(Japan)addone(china)print len(country_counter) A.0B.1C.2D.3E.444. What gets printed?(D)confusion = confusion1 = 1confusion1 = 2confusion1 += 1sum = 0for k in confusion: sum += confusionkprint sum A.1B.2C.3D.4E.545. What gets printed?(C)confusion = confusion1 = 1confusion1 = 2confusion1.0 = 4sum =
26、 0for k in confusion: sum += confusionkprint sum A.2B.4C.6D.7E.An exception is thrown46.What gets printed?(E)boxes = jars = crates = boxescereal = 1boxescandy = 2jarshoney = 4cratesboxes = boxescratesjars = jarsprint len(cratesboxes)A.1B.2C.4D.7E.An exception is thrown47. What gets printed?(E)number
27、Games = numberGames(1,2,4) = 8numberGames(4,2,1) = 10numberGames(1,2) = 12sum = 0for k in numberGames: sum += numberGameskprint len(numberGames) + sum A.8B.12C.24D.30E.3348. What gets printed?(A)foo = 1:1, 2:2, 3:3foo = print len(foo) A.0B.1C.2D.3E.An exception is thrown49. What gets printed?(B)foo = 1:1, 2:2, 3:3del foo1foo1
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1