Python for loop?

前端 未结 6 1528
醉酒成梦
醉酒成梦 2021-01-24 10:04

I am having trouble understanding a Python for loop. For example, here is some code I\'ve made while I\'m learning:

board = []
for i in range (0,5):
    board.ap         


        
6条回答
  •  太阳男子
    2021-01-24 10:22

    It's an iterator, you can see it as a bucket that stores the result of each iteration; the thing that adds confusion is the fact that it's simply unused in your script, this is another script with a "more involved" use of iterators.

    fruits = ['banana', 'apple', 'strawberry', 'coconut', 'cherry']
    for yup in fruits:
      print(yup)
    

    as you can see you can name it as you want, it's the syntax that makes that word an iterator.

提交回复
热议问题