Python For Loop: Simple Example and Explanation
Here is an example of a simple 'for' loop in Python:
# Loop through a list of numbers and print each one
numbers = [1, 2, 3, 4, 5]
for num in numbers:
print(num)
This code will output:
1
2
3
4
5
In this example, we define a list of numbers and then use a 'for' loop to iterate over each number in the list. The 'num' variable represents the current number in the loop, and we use the 'print()' function to output it to the console. The loop will continue until it has gone through every item in the list.
原文地址: https://www.cveoy.top/t/topic/mF9q 著作权归作者所有。请勿转载和采集!