for
` loop :# Using the for loop to iterate over a list of numbers
numbers = [1, 2, 3, 4, 5]
for number in numbers:
print(number)
# Using the for loop to iterate over a string
word = "hello"
for letter in word:
print(letter)
1
2
3
4
5
h
e
l
l
o
for
` loop to iterate over a list of numbers and a string. Inside the loop, we use the `print()
` function to print each item in the list and each character in the string.for
` loop to iterate over a sequence of items such as a list, string, or tuple. The loop will execute once for each item in the sequence, and the loop variable (in this case, `number
` and `letter
`) will take on the value of each item in turn.