List Iteration in Python

Level 254 keystrokes

This loops through a list of fruits and prints each one. The for loop iterates over each element in the list.

Python code

# Create a list containing two fruit names as strings
1fruits = ["apple", "banana"]
# for loop iterates through each item in the list
# f is a variable that holds the current item
2for f in fruits:
# First iteration: f = "apple"
# Second iteration: f = "banana"
3 print(f)

Output

apple
banana
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this Python code and how often they appear.

  • "× 4
  • ,× 1
  • :× 1
  • (× 1
  • )× 1
  • [× 1
  • ]× 1
  • =× 1

More Python examples at level 2

← Python typing practice