Here is an example of a Python for loop:

# loop through a list of numbers and print each one
numbers = [1, 2, 3, 4, 5]
for num in numbers:
    print(num)

This loop iterates through the 'numbers' list and assigns each value to the variable 'num'. It then prints out the value of 'num' for each iteration of the loop.

Here is another example that uses a range of numbers:

# loop through a range of numbers and print each one
for i in range(1, 6):
    print(i)

This loop uses the 'range()' function to generate a sequence of numbers from 1 to 5. It then iterates through that sequence and prints out each number.

Python For Loop: A Beginner's Guide with Examples

原文地址: https://www.cveoy.top/t/topic/mHbX 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录