Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/316.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/7/python-2.7/5.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_Python 2.7 - Fatal编程技术网

Python 从数组中拆分值

Python 从数组中拆分值,python,python-2.7,Python,Python 2.7,我正在编写python脚本,计算从0开始到17的每个值 以下是我使用的: row = range(0, 18) print row 结果: 19:39:14 T:5816 NOTICE: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17] 我想得出这样的结果: >>> 0 >>> 1 >>> 2 >>> 3 >>> 4 >

我正在编写python脚本,计算从0开始到17的每个值

以下是我使用的:

row = range(0, 18)
print row
结果:

19:39:14 T:5816  NOTICE: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]
我想得出这样的结果:

>>> 0
>>> 1
>>> 2
>>> 3
>>> 4
>>> 5
>>> 6
>>> 7
>>> 8
>>> 9
>>> 10
>>> 11
>>> 12
>>> 13
>>> 14
>>> 15
>>> 16
>>> 17
您能告诉我如何从数组中分割值,以便像上面显示的那样打印每个值吗

编辑:您可以看到为什么我不想使用for循环,是因为我想生成id以使用for循环之外的变量,并且我想从数组中获取元素列表,以便存储在数据库中。否则它将发射数千次


您可能希望迭代数组。这通常是使用for循环生成的

编辑:您可能还希望使用更实用的方法。您可以使用打印功能映射阵列。print是Python3中的一个函数,因此如果您使用的是Python2.7,其中print是语言表达式,那么您需要使用


您应该阅读Python中的输入和输出

至于你的问题,你可以这样打印出来-

for number in range(18):
    print number

谢谢,但我不想使用for循环,因为我想让它在循环之外与变量程序_id一起工作。没有循环,还有其他方法可以使用吗?如果for块在同一个函数范围内,可以在for块内使用program_id。在这里阅读python变量作用域:@Danny,program_id到底是什么?@PadraicCunningham这是我正在生成的实际id,从3002一直到3485。@Danny,我仍然无法理解您的逻辑。@thomas谢谢,但我不想使用for循环,因为我使用的是for循环之外的变量,所以如何计算每行的值?有点像使用分割法?有人理解这个问题吗?
for number in row:
    print number
from __future__ import print_function
map(print, row)
for number in range(18):
    print number