for _ in range(n)
'_'表示占位符,表示对于变量的值为多少不重要,因为其在下面的循环中不会用到,只是起到循环n次的作用
举例:
>>> count = [0 for _ in range(100)]
>>> count
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
>>> len(count)
100
随机生成100以内的数一百次
>>> lst = [random.randint(0,100) for _ in range(100)]
>>> len(lst)
100
>>> lst
[73, 24, 68, 70, 27, 58, 19, 90, 10, 66, 75, 90, 79, 95, 84, 38, 97, 58, 1, 25, 95, 43, 7, 74, 89, 22, 98, 95, 28, 23, 18, 51, 68, 60, 58, 48, 88, 31, 90, 56, 63, 38, 50, 95, 28, 3, 5, 38, 73, 77, 21, 51, 23, 35, 62, 35, 32, 52, 6, 87, 59, 29, 11, 19, 13, 20, 23, 86, 92, 71, 77, 77, 55, 22, 14, 98, 82, 45, 64, 59, 37, 44, 28, 34, 50, 4, 59, 89, 18, 7, 20, 6, 2, 52, 88, 27, 82, 53, 8, 6]
|