Why do I not have to define the variable in a for loop using range(), but I do have to in a while loop in Python?

后端 未结 6 678
悲哀的现实
悲哀的现实 2021-01-18 17:36

I have the following code using a for loop:

    total = 0
    for num in range(101):
       total = total + num
       print(total)

Now the

6条回答
  •  情话喂你
    2021-01-18 18:02

    If you are coming from other programming languages like C, C++ or Java then do not confuse with for in loop of python.

    In python, for in loop pick one item from list of items and does something with help of the picked item.

提交回复
热议问题