1 以下代码的输出结果为:
print(eval(‘[1+2, 3]’))
A.报错 B.‘[1+2, 3]’ C.[1+2, 3] D.[3, 3]
2 以下代码的输出结果为:
from fractions import Fraction
f = Fraction(2, 3)
print(f + 1)
print(f + Fraction(2, 3))
A.1.6666666666666665 4/3
B.1.6666666666666665 1.3333333333333333
C.5/3 4/3
D.5/3 1.3333333333333333
3 关于以下代码,说法正确的是:
import decimal
print(0.1 + 0.2)
print(decimal.Decimal(0.1) + decimal.Decimal(0.2))
print(decimal.Decimal(‘0.1’) + decimal.Decimal(‘0.2’))
A.输出3个0.3
B.第一个是不精确的0.3,后两个是0.3
C.前两个是不精确的0.3,最后一个是0.3
D.输出3个不精确的0.3
4 以下代码的输出结果为:
a = []
a.append
print(a)
A.报错 B.[] C.[None] D.None
5 以下代码的输出结果为:
glb = 123
def test():
import __main__
print(__main__.glb)
glb = 456
print(glb)
test()
print(glb)
A.报错 B.123 456 123
C.123 456 456 D.123 123 123
6 以下代码的输出结果为:
sizes = [‘S’,‘M’]
colors = [‘white’,‘black’]
shirts = [(size,color) for color in colors for size in sizes]
print(shirts)
A.[(‘S’, ‘white’), (‘S’, ‘black’), (‘M’, ‘white’), (‘M’, ‘black’)]
B.[(‘S’, ‘white’), (‘M’, ‘white’), (‘S’, ‘black’), (‘M’, ‘black’)]
C.[(‘S’, ‘white’), (‘M’, ‘black’)]
D.[(‘white’, ‘S’), (‘black’, ‘M’)]、
7 以下代码的输出结果为:
def f(x):
if x == 0:
return 0
elif x == 1:
return 1
else:
return (x*f(x-1))
print(f(5))
A.120
B.720
C.24
D.64
8 以下代码的输出结果为:
def outer(fn):
print('outer')
def inner():
print('inner')
return fn
return inner
@outer
def fun():
print('fun')
A.outer B.inner C.fun D.无输出
9 以下代码的输出结果为:
for i in range(3):
if i == 2:
break
print(i)
else:
print('end')
A.0 1 B.0 1 end C.0 1 2 D.0 1 2 end
10 以下代码的输出结果为:
lst = [[1,2], [3,4], [5,6]]
print(list(zip(*lst)))
A.报错 B. [[1,2,3,4,5,6]
C.[[1, 3, 5], [2, 4, 6]] D.[(1, 3, 5), (2, 4, 6)]
11 以下代码的输出结果为:
lst=[1,2,3,4]
print(sum(x for x in lst))
A.报错 B. 10 C.24 D.4
12 以下代码的输出结果为:
alist = [3, 'd' in 'abc', {1,2}=={2,1}]
print(any(alist))
print(all(alist))
A.True True B. True False C.False True D.False False
13 以下代码的输出结果为:
x = [-2,-1,0,1,2]
def test(x):
return x**2-2*x
print(max(x,key=test))
A.-2 B. 8 C.2 D.0
14 以下代码的输出结果为:
>>> lst = [2,3,4,5,2,3,2,2,4]
>>> max(set(lst),key=lst.count)
A.5 B. 4 C.3 D.2
15 以下代码的输出结果为:
lis = ['apple','lemon','pear','peach']
def fn(x):
return x[::-1]
lis.sort(key=fn,reverse=True)
print(lis)
A.[‘apple’, ‘lemon’, ‘peach’,‘pear’]
B.[‘pear’, ‘peach’, ‘lemon’, ‘apple’]
C.[‘apple’,‘pear’, ‘lemon’, ‘peach’]
D.[‘pear’, ‘lemon’, ‘peach’, ‘apple’]
答案:DCCBB BAAAD BBADD
部分试题来自牛客网