1、如下python代码段;运行结果正确的是(C).
b1 = [1,2,3]
b2 = [2,3,4]
b3 = [val for val in b1 if val in b2]
print(b3)
A:[1,2,3,4]
B:[2]
C:[2,3]
D:程序有误
解析:b3为
①定义一个变量val;
②
for val in b1:
if val in b2:
print(val)
2、python中,下列对程序描述正确的是(B)
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]
解析:append():在列表末尾添加一个新的元素。