How to change for-loop iterator variable in the loop in Python?

后端 未结 5 1520
旧巷少年郎
旧巷少年郎 2021-01-22 05:02

I want to know if is it possible to change the value of the iterator in its for-loop?

For example I want to write a program to calculate prime factor of a number in the

5条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-22 05:24

    No.

    Python's for loop is like other languages' foreach loops. Your i variable is not a counter, it is the value of each element in a list, in this case the list of numbers between 2 and number+1. Even if you changed the value, that would not change what was the next element in that list.

提交回复
热议问题