Python测试题(附答案)

1 float(False)的结果为:
A.报错 B.inf C.0.0 D.1.0

2 a=[1,2,3][False];print(a)的结果为:
A.报错 B.1 C.2 D.3

3 i=1;print(++i)的结果为:
A.无限循环 B.报错 C.1 D.2

4 i=1;print(i++)的结果为:
A.无限循环 B.报错 C.1 D.2

5 print(~True)和print(~False)的结果为:
A.False,True B.0,1 C.-1,0 D.-2,-1

6 print(02)的结果为:
A.报错 B.2 C.2.0 D.0.2

7 print(False<1)的结果为:
A.报错 B.True C.False D.None

8 以下代码的输出结果为:

lists = [1, 2, 3, 4, 5, 6]
lists.append([7,8,9])
print(lists)

A.[1,2,3,4,5,6] B.[1,2,3,4,5,6,7,8,9] C.[1,2,3,4,5,6,[7,8,9]] D.[7,8,9]

9 以下代码的输出结果为:

for i in 'python':
    if i == 'h':
        break
	print(i)

A.‘p’,‘y’,‘t’ B.‘p’,‘y’,‘t’,‘h’ C.‘p’,‘y’,‘t’,‘h’,‘o’,‘n’ D.‘pyt’

10 以下代码的输出结果为:

lists = [1, 2, 3, 4]
tmp = 0
for i,j in enumerate(lists):
    tmp += i * j
print(tmp)

A.20 B.30 C.100 D.None

11 以下代码的输出结果为:

one = (1, 2, 3)
two = ('a', 'b')
print(one+two)

A.报错 B.None C.[1, 2, 3, ‘a’, ‘b’] D.(1, 2, 3, ‘a’, ‘b’)

12 以下代码的输出结果为:

a = [1]
b = 2
c = 1
def fn(lis,obj):
    lis.append(b)
    obj = obj + 1
    return lis,obj
fn(a,c)
print(fn(a,c))

A.([1, 2, 2], 2) B.([1, 2, 2], 3) C.([1, 2], 2) D.([1, 2], 3)

13 print(float(‘12E3’))的结果为:
A.报错 B.12.3 C.12000 D.12000.0

14 print( {‘a’,‘b’,‘c’} - {‘b’,‘d’} )的结果为:
A.报错 B.{‘a’, ‘c’} C.{‘a’, ‘c’, ‘d’} D.{‘a’, ‘b’, ‘c’, ‘d’}

15 以下代码的输出结果为:

dicts = {'one': 1, 'two': 2, 'three': 3}
dicts['four'] = 4
dicts['one'] = 6
print(dicts)

A.{‘one’: 1, ‘two’: 2, ‘three’: 3, ‘four’: 4} B.{‘one’: 6, ‘two’: 2, ‘three’: 3}
C.{‘one’: 1, ‘two’: 2, ‘three’: (3, 4)} D.{‘one’: 6, ‘two’: 2, ‘three’: 3, ‘four’: 4}

16 以下代码的输出结果为:

tmp = [2, 1, 5, 4, 7]
print(max(tmp))
print(tmp.index(max(tmp)))

A.7,1 B. 5,2 C. 7,4 D. 7,5

17 下列哪个语句在Python中是非法的?
A.x = y = z = 1 B.x = (y = z + 1) C.x, y = y, x D.x += y

18 执行下列选项代码,输出[1, {‘age’: 10}]的是:
A.

a = [1,{'age':10}]
b = a
a[1]['age'] = 12
print(b)

B.

a = [1,{'age':10}]
b = a[:]
a[1]['age'] = 12
print(b)

C.

a = [1,{'age':10}]
b = a.copy()
a[1]['age'] = 12
print(b)

D.

import copy
a = [1,{'age':10}]
b = copy.deepcopy(a)
a[1]['age'] = 12
print(b)

19 以下代码的输出结果为:

lists = [1, 2, 2, 3, 3, 3]
print(lists.count(3))
print(lists.pop())
lists.pop()
print(lists)

A.2,3,[1, 2, 2, 3] B.3,3,[1, 2, 2, 3]
C.3,3,[1, 2, 2, 3, 3] D.2,3,[1, 2, 2, 3, 3]

20 以下代码的输出结果为:

strs = ' I like python '
one = strs.split(' ')
two = strs.strip()
print(one)
print(two)

A.[‘’, ‘I’, ‘like’, ‘python’, ‘’],‘I like python ’
B.[‘I’, ‘like’, ‘python’],‘I like python’
C.[’', ‘I’, ‘like’, ‘python’, ‘’],‘I like python’
D.[‘I’, ‘like’, ‘python’],'I like python ’

答案:CBCBD ABCAA DADBD CBDBC

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值