以下这段代码,转换成列表推导式,最合适的是( )。 squared = [] for x in range(10): squared.append(x**2)
A. squared = [x**2 for x in range(10)]
B. squared = [x for x**2 in range(10)]
C. squared = [x for x in range(10)]
D. squared = [xfor x in range(10)**2 ]
查看答案
x = [ i for i in range(0, 10, 3) if i % 2==0],则x为( )。
A. [0, 6]
B. [6]
C. [6,]
D. [4,6]
表达式[x for x in [1,2,3,4,5] if x < 3]的值为( )。
A. [1,2,3]
B. [1]
C. [1,2]
D. [0,1,2]
表达式[x*3 for x in range(1,10) if x%2==1]的值为( )。
A. [3,9,15,21]
B. [3,9,15,21,27]
C. [9,15,21,27]
D. [9,15,21]
若有一个列表a,现需计算出列表a中所有元素平方值所对应的列表,可以表示为( )。
A. [x**2 for x in a]
B. [x*2 for x in a]
C. [x^2 for x in a]
D. [x%2 for x in a]