Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Python中创建序列_Python - Fatal编程技术网

在Python中创建序列

在Python中创建序列,python,Python,是否有一种方法可以创建一个列表,其中包含每个60的a和b之间的所有数字,而不使用循环?假设a和b之间的间隔大于60。您需要函数。如果是蟒蛇2: >>> a = 1 >>> b = 1260 >>> range(a, b, 60) [1, 61, 121, 181, 241, 301, 361, 421, 481, 541, 601, 661, 721, 781, 841, 901, 961, 1021, 1081, 1141, 1201]

是否有一种方法可以创建一个列表,其中包含每个
60
a
b
之间的所有数字,而不使用循环?假设
a
b
之间的间隔大于60。

您需要函数。如果是蟒蛇2:

>>> a = 1
>>> b = 1260
>>> range(a, b, 60)
[1, 61, 121, 181, 241, 301, 361, 421, 481, 541, 601, 661, 721, 781, 841, 901, 961, 1021, 1081, 1141, 1201]
对于python3,您需要从中列出一个列表:

>>> a = 1
>>> b = 1260
>>> range(a, b, 60)
range(1, 1260, 60)
>>> list(range(a, b, 60))
[1, 61, 121, 181, 241, 301, 361, 421, 481, 541, 601, 661, 721, 781, 841, 901, 961, 1021, 1081, 1141, 1201]