Python For Loop: Simple Example & Explanation
Here's a simple Python for loop example:
# Define a list of numbers
numbers = [1, 2, 3, 4, 5]
# Loop through each number in the list and print it
for num in numbers:
print(num)
Output:
1
2
3
4
5
In this example, we define a list of numbers and use a for loop to iterate through each number in the list. The loop variable 'num' takes on the value of each number in the list in turn, and we use the 'print' statement to display each number on a new line.
原文地址: https://www.cveoy.top/t/topic/mF8B 著作权归作者所有。请勿转载和采集!