For in Python 3.10

Find this useful? Support us: Star on GitHub 6
Category: Loop | Language: Python 3.10

Certainly.

In Python 3.10, the for loop is used to iterate over a sequence of values. Here are some examples:

1. Loop over a list:

   names = ['Alice', 'Bob', 'Charlie']
for name in names:
print(name)

Output:
   Alice
Bob
Charlie


2. Loop over a range of numbers:

   for i in range(5):
       print(i)
   
Output:
   0
   1
   2
   3
   4
   
3. Loop over a string:
   message = 'Hello, World!'
   for char in message:
       print(char)
   
Output:
   H
   e
   l
   l
   o
   ,
    
   W
   o
   r
   l
   d
   !
   

4. Loop over a dictionary:

   scores = {'Alice': 90, 'Bob': 80, 'Charlie': 70}
for name, score in scores.items():
print(name, score)

Output:
   Alice 90
Bob 80
Charlie 70


I hope this helps! Let me know if you have any questions.