1. 已知列表x=list(range(9)),那么执行语句del x[:2]之后,x的值为(D)
A.[1,3,5,7,9]
B.[1,3,5,7]
C.[0,1,3,5,7]
D.[2,3,4,5,6,7,8]
2. len(range(1,10))的值是(B)
A.8 B.9 C.10 D.11
3. 表达式",".join(list)中list是列表类型,以下选项中对其功能的描述正确的是(D)
A.将逗号字符串增加到列表list中
B.在列表list每个元素后增加一个逗号
C.将列表所有元素连接成一个字符串,每个元素后增加一个逗号
D.将列表所有元素连接成一个字符串,元素之间增加一个逗号
list1 = ['1', '2', '3', '4', '5']
str1 = ",".join(list1)
print(str1, type(str1))
运行结果:
1,2,3,4,5 <class 'str'>
4. 表达式[1,2,3]*3的执行结果为(A)
A.[1,2,3,1,2,3,1,2,3]
B.{[1,2,3],[1,2,3],[1,2,3]}
C.[1,2,3],[1,2,3],[1,2,3]
D.([1,1,1,2,2,2,3,3,3])
list1 = [1, 2, 3]
print(list1*3)
运行结果:
[1, 2, 3, 1, 2, 3, 1, 2, 3]
5. 假设列表对象aList的值为[3,4,5,6,7,9,11,13,15,17],那么切片aList[3:7]得到的值是(B)
A.[5,6,7,9,11]
B.[6,7,9,11]
C.[5,6,7,9,]
D.[7,9,11,13]
6. 已知x=list(range(20)),那么表达式x[-1]的值为(D)。
A.0 B.1 C.20 D.19
7. 切片操作list(range(6))[::2]执行结果为(D)
A.[0,1] B.[0,2,4,6] C.[0,1,2] D.[0,2,4]
list1 =list(range(6))
print(list1[::2])
运行结果:
[0, 2, 4]
8. 已知x=[3,7,5],那么执行语句x=x.sort(reverse=True)之后,x的值为(B)
A.[3,5,7] B.[7,5,3] C.None D .[3,7,5]
9. 下面程序输出是什么?D
txt=["a","b","c","d","e"]
stop_words=["d","i"]
t=[x for x in txt if x not in stop_words]
print(t)
A.["a","b","c","d","e"]
B.["a","b","c","d"]
C.["a","b","c"]
D.["a","b","c",”e”]
txt = ["a", "b", "c", "d", "e"]
stop_words = ["d", "i"]
t = [x for x in txt if x not in stop_words]
print(t)
运行结果:
['a', 'b', 'c', 'e']
10. 下面程序的输出是:C
ls=["abcd","ab","cd","cdab"]
n,m=0,0
for line in ls:
if "ab" and "cd" in line:
n+=1
m+=1
elif "ab" in line:
n+=1
elif "cd" in line:
m+=1
print (n,m)
A:3 3 B:3 4 C:4 3 D:4 4
ls = ["abcd", "ab", "cd", "cdab"]
n, m = 0, 0
for line in ls:
if "ab" and "cd" in line:
n += 1
m += 1
elif "ab" in line:
n += 1
elif "cd" in line:
m += 1
print(n, m)
运行结果:
4 3
11. 以下程序的输出结果是( A):
ls=[11,22,33,44]
for i in ls:
if i=="33":
print("找到!i=",i)
break
else
print("未找到...")
A: 未找到...
B: 未找到... 未找到... 找到!I=33
C:未找到... 未找到... 未找到... 未找到...
D:找到!I=33
ls=[11,22,33,44]
for i in ls:
if i=="33":
print("找到!i=",i)
break
else:
print("未找到...")
运行结果:
未找到...
12. 以下程序的输出结果是(C ):
k=0
for i in range (4):
for j in range(i+1):
k+=j
if j>1:
break
print(k)
A:5 B:6 C:7 D:8
k=0
for i in range (4):
for j in range(i+1):
k+=j
if j>1:
break
print(k)
运行结果:
7
13. 列表可以作为字典的“键”。
错
13. Python列表属于无序序列。
错
14. Python列表中所有元素必须为相同类型的数据。
错
16. 对于列表而言,在尾部追加元素比在中间位置插入元素速度更快一些,尤其是对于包含大量元素的列表。
对
17. 使用Python列表的方法insert()为列表插入元素时会改变列表中插入位置之后元素的索引。
对
18.已知列表x=[1,3,2],那么执行语句x=x.reverse()之后,x的值为_____2,3,1_______。
19.已知x=([1],[2]),那么执行语句x[0].append(3)后x的值为________([1,3],[2])________。
20.编程题:有一个list1列表存储2-99的数据,查找孪生素数后输出,孪生素数:两个素数之间间隔为2
list1=list(range(2,100))
list2=[]
for i in list1:
for j in range(2,i):
if i%j==0:
break
else:
list2.append(i)
print(list2)
for i in range(1,len(list2)):
if list2[i]-list2[i-1]==2:
print(list2[i-1],'与',list2[i],'是孪生素数')
运行结果:
[3, 5, 5, 5, 7, 7, 7, 7, 7, 9, 11, 11, 11, 11, 11, 11, 11, 11, 11, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 15, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 21, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 25, 25, 25, 27, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 33, 35, 35, 35, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 39, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 45, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 49, 49, 49, 49, 49, 51, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 55, 55, 55, 57, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 63, 65, 65, 65, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 69, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 75, 77, 77, 77, 77, 77, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 81, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 85, 85, 85, 87, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 91, 91, 91, 91, 91, 93, 95, 95, 95, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 99]
3 与 5 是孪生素数
5 与 7 是孪生素数
7 与 9 是孪生素数
9 与 11 是孪生素数
11 与 13 是孪生素数
13 与 15 是孪生素数
15 与 17 是孪生素数
17 与 19 是孪生素数
19 与 21 是孪生素数
21 与 23 是孪生素数
23 与 25 是孪生素数
25 与 27 是孪生素数
27 与 29 是孪生素数
29 与 31 是孪生素数
31 与 33 是孪生素数
33 与 35 是孪生素数
35 与 37 是孪生素数
37 与 39 是孪生素数
39 与 41 是孪生素数
41 与 43 是孪生素数
43 与 45 是孪生素数
45 与 47 是孪生素数
47 与 49 是孪生素数
49 与 51 是孪生素数
51 与 53 是孪生素数
53 与 55 是孪生素数
55 与 57 是孪生素数
57 与 59 是孪生素数
59 与 61 是孪生素数
61 与 63 是孪生素数
63 与 65 是孪生素数
65 与 67 是孪生素数
67 与 69 是孪生素数
69 与 71 是孪生素数
71 与 73 是孪生素数
73 与 75 是孪生素数
75 与 77 是孪生素数
77 与 79 是孪生素数
79 与 81 是孪生素数
81 与 83 是孪生素数
83 与 85 是孪生素数
85 与 87 是孪生素数
87 与 89 是孪生素数
89 与 91 是孪生素数
91 与 93 是孪生素数
93 与 95 是孪生素数
95 与 97 是孪生素数
97 与 99 是孪生素数