#列表中每个数值乘三 vec = [2,4,6] print([3*x for x in vec]) #[6, 12, 18] #if过滤器 print([3*x for x in vec if x > 3]) #[12, 18] #嵌套 var1 = [1,2,3] var2 = [4,5,6] print([x*y for x in var1 for y in var2]) #[4, 5, 6, 8, 10, 12, 12, 15, 18]
#列表中每个数值乘三 vec = [2,4,6] print([3*x for x in vec]) #[6, 12, 18] #if过滤器 print([3*x for x in vec if x > 3]) #[12, 18] #嵌套 var1 = [1,2,3] var2 = [4,5,6] print([x*y for x in var1 for y in var2]) #[4, 5, 6, 8, 10, 12, 12, 15, 18]