Count indexes using “for” in Python

后端 未结 7 1307
清歌不尽
清歌不尽 2021-02-01 01:44

I need to do in Python the same as:

for (i = 0; i < 5; i++) {cout << i;} 

but I don\'t know how to use FOR in Python to get the index

相关标签:
7条回答
  • 2021-02-01 02:23

    Just use

    for i in range(0, 5):
        print i
    

    to iterate through your data set and print each value.

    For large data sets, you want to use xrange, which has a very similar signature, but works more effectively for larger data sets. http://docs.python.org/library/functions.html#xrange

    0 讨论(0)
提交回复
热议问题