Count indexes using “for” in Python

后端 未结 7 1309
清歌不尽
清歌不尽 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条回答
  •  梦毁少年i
    2021-02-01 02:13

    In additon to other answers - very often, you do not have to iterate using the index but you can simply use a for-each expression:

    my_list = ['a', 'b', 'c']
    for item in my_list:
        print item
    

提交回复
热议问题