100以内奇数:
ls = [x for x in range(100) if x % 2 == 1]
100以内偶数:
ls = list(x for x in range(100) if x % 2 == 0)
20以内的2次方:
ls = list(x * x for x in range(20))
斐波那契数列 Fibonacci :
1、1、2、3、5、8、13、21、34 …… 数列特点:该数列从第三项开始,每个数的值为其前两个数之和
ls = [1, 1]
for i in range(2, 20):
ls.append(ls[i - 2] + ls[i - 1])
print(ls)
产生10个随机数:
import random s100 = [random.randint(1, 101) for x in range(10)] #产生10个100以内的随机数
print(s100) s0 = [x for x in range(1, 101)]
s1 = random.sample(s0, 10) # 产生10个100以内随机数(不重复的)
print(s0)
print(s1)
试一下:
import copy
a = True
a = 123
a = ""
a = (1, 2, 3) #以上几种,abc的id都一样 a = [1, 2, 3] #list的拷贝、深拷贝的id不一样
a = {"x":1,"y":2} #dict的拷贝、深拷贝的id不一样 b = copy.copy(a)
c = copy.deepcopy(a) print(id(a))
print(id(b))
print(id(c))
.