Python For Loop: A Beginner's Guide with Examples
Here is an example of a basic for loop in Python:
# iterate through a list of numbers and print each one
numbers = [1, 2, 3, 4, 5]
for num in numbers:
print(num)
This loop will go through each number in the 'numbers' list and print it to the console. The 'num' variable is assigned the value of each number in turn as the loop iterates. The output of this code would be:
1
2
3
4
5
原文地址: https://www.cveoy.top/t/topic/mF9Q 著作权归作者所有。请勿转载和采集!