1.what does thefollowing code do?(B)
def a(b, c, d): pass
A.defines a list andinitializes it
B.defines afunction, which does nothing
C.defines a function,which passes its parameters through
D.defines an emptyclass
2.what gets printed?Assuming python version 2.x(A)
print type(1/2)
A.
B.
C.
D.
E.
3. what is the outputof the following code?(E)
print type([1,2])
A.
B.
C.
D.
E.
4. what gets printed?(C)
def f(): pass
print type(f())
A.
B.
C.
D.
E.
5. what should thebelow code print?(A)
print type(1J)
A.
B.
C.
D.
E.
6. what is the outputof the following code?(D)
print type(lambda:None)
A.
B.
C.
D.
E.
7. what is the outputof the below program?(D)
a = [1,2,3,None,(),[],]
print len(a)
A.syntax error
B.4
C.5
D.6
E.7
8.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 * 2
t = lambda p: p * 3
x = 2
x = d(x)
x = t(x)
x = d(x)
print x
A.7
B.12
C.24
D.36
E.48
10. What gets printed?(B)
x = 4.5
y = 2
print x//y
A.2.0
B.2.25(Python自动类型转换)
C.9.0
D.20.25
E.21
11. What gets printed?(C)
nums = set([1,1,2,3,3,3,4])
print len(nums)
A.1
B.2
C.4 (set集合去重)
D.5
E.7
12. What gets printed?(A)
x = True
y = False
z = False
if x or y and z:
print "yes"
else:
print "no"
A.yes (y andz之后, 再与x or)
B.no
C.fails to compile
13. What gets printed?(C)
x = True
y = False
z = False
if not x or y: (flase)
print 1
elif not x or not y and z: (flase)
print 2
elif not x or y or not y and x: (true)
print 3
else:
print 4
A.1
B.2
C.3 (True,Python 优先级or>and>not)
D.4
14. If PYTHONPATH isset in the environment, which directories are searched for modules?(D)
A) PYTHONPATH directory
B) current directory
C) home directory
D) installation dependent default path
A.A only
B.A and D
C.A, B, and C
D.A, B, and D
E.A, B, C, and D
15. In python 2.6 orearlier, the code will print error type 1 if accessSecureSystem raises anexception of either AccessError type or SecurityError type(B)
try:
accessSecureSystem()
except AccessError, SecurityError:
print "error type 1"
continueWork()
A.true
B.false
16. The following codewill successfully print the days and then the months(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. Assuming python 2.6what gets printed?(A)
f = None
for i in range (5):
withopen("data.txt", "w") as f:
if i> 2:
break
print f.closed
A.True (打印3个True)
B.False
C.None
18. What gets printed?(C)
counter = 1
def doLotsOfStuff():
global counter
for i in (1, 2, 3):
counter += 1
doLotsOfStuff()
print counter
A.1
B.3
C.4(循环3次)
D.7
E.none of the above
19. What gets printed?(C)
print r"\nwoow"
A.new line then thestring: woow
B.the text exactly likethis: r"\nwoow"
C.the textlike exactly like this: \nwoow(打印原始字符)
D.the letter r and thennewline then the text: woow
E.the letter r then thetext like this: nwoow
20.What gets printed?(B)
print "hello" 'world'
A.on one line the text:hello world
B.on one linethe text: helloworld(简单的字符串拼接)
C.hello on one line andworld on the next line
D.syntax error, thispython program will not run
21.What gets printed?(E)
print "\x48\x49!"
A.\x48\x49!
B.4849
C.4849!
D. 48 49!
E.HI!(转义ASCII码)
22. What gets printed?(D)
print 0xA + 0xa
A.0xA + 0xa
B.0xA 0xa
C.14
D.20(两个16进制的10相加)
E.0x20
23. What gets printed?(E)
class parent:
def __init__(self, param):
self.v1 = param
class child(parent):
def __init__(self, param):
self.v2 = param
obj = child(11)
print "%d %d" % (obj.v1, obj.v2)
A.None None
B.None 11
C.11 None
D.11 11
E.Error isgenerated by program(AttributeError: child instance has no attribute 'v1')
classchild(parent):
def __init__(self,param):
parent.__init__(self,param)
self.v2 = param
没有实例化
24. What gets printed?(E)
kvps ={"user","bill", "password","hillary"}
print kvps['password']
A.user
B.bill
C.password
D.hillary
E.Nothing.Python syntax error (“{}”表示集合的意思,无法输出)
25. What gets printed?(B)
66% on 1871 times asked
class Account:
def __init__(self, id):
self.id = id
id = 666
acc = Account(123)
print acc.id
A.None
B.123(区分成员变量和局部变量)
C.666
D.SyntaxError, thisprogram will not run
26. What gets printed?(C)
name = "snow storm"
print "%s" % name[6:8]
A.st
B.sto
C.to(从0开始,输出6,7)
D.tor
E.Syntax Error
27. What gets printed?(D)
name = "snow storm"
name[5] = 'X'
print name
A.snow storm
B.snowXstorm
C.snow Xtorm
D.ERROR, thiscode will not run(字符串是常亮)
28. Which numbers areprinted?(C)
for i in range(2):
print i
for i in range(4,6):
print i
A.2, 4, 6
B.0, 1, 2, 4, 5, 6
C.0, 1, 4, 5(第一个从0开始,剩下的是一个区间)
D.0, 1, 4, 5, 6, 7, 8,9
E.1, 2, 4, 5, 6
29. What sequence ofnumbers is printed?(B)
values = [1, 2, 1, 3]
nums = set(values)
def checkit(num):
if num in nums:
return True
else:
return False
for i in filter(checkit, values):
print i
A.1 2 3
B.1 2 1 3(表示values链表中的元素是否在集合内)
C.1 2 1 3 1 2 1 3
D.1 1 1 1 2 2 3 3
E.Syntax Error
30. What sequence ofnumbers is printed?(E)
values = [2, 3, 2, 4]
def my_transformation(num):
return num ** 2
for i in map(my_transformation,values):
print i
A.2 3 2 4
B.4 6 4 8
C.1 1.5 1 2
D.1 1 1 2
E.4 9 4 16(双乘号表示幂的意思)