Python for loop examples

Example 1:

friends = ["Rolf", "Jen", "Anne"]
for friend in friends:
  print(friend)
Example 2:
elements = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
for _ in elements:
  print("Hello world!")
Example 3:
for index in range(10):
  print(index)
Example 4:
for index in range(5, 10):
  print(index)
Output:
5
6
7
8
9
Example 5:
for index in range(2, 20, 3):
  print(index)
Output:
2
5
8
11
14
17
Example 6:
students = [
    {"name": "Rolf", "grade": 90},
    {"name": "Bob", "grade": 70},
    {"name": "Jen", "grade": 100},
    {"name": "Anne", "grade": 80}
]
for student in students:
  name = student["name"]
  grade = student["grade"]
  print(f"{name} has a grade of {grade}.")
Output:
Rolf has a grade of 90.
Bob has a grade of 70.
Jen has a grade of 100.
Anne has a grade of 80.