num = [1,2,3]
for x in num:
x=x*3
print(num)
这打印1,2,3
new_list=[]
for x in range(len(num))
new_list = x[num]*3 + new_list[]
我想要3,6,9
答案 0 :(得分:0)
num = [1,2,3]
for i in range(len(num)):
num[i] = num[i] * 3
print(num)
答案 1 :(得分:0)
您可以使用范围:
直接生成步长为3的列表first = 3
num_elements = 3
step = 3
nums = range(first, first + step*num_elements, step) # Python2
# nums = list(range(first, first + step*num_elements, step)) # Python3
或更简洁, nums = range(3,12,3)#Python2 #ums = list(范围(3,12,3))#Python3
或者,如果您的列表已经给出,您可以使用列表理解
initial = [1,2,3]
nums = [3*elem for elem in initial]