Python for Keyword

Example

Print each number from 1 to 8:

for x in range(1, 9):
  print(x)

Run Example

Definition and Usage

The for keyword is used to create a for loop.

It can be used to traverse sequences, such as lists, tuples, etc.

More Examples

Example

Traverse each item in the list:

fruits = ["apple", "banana", "cherry"]
for x in fruits:
  print(x)

Run Example

Related Pages

Use break Keyword Interrupt the loop.

Use continue Keyword End the current iteration but continue the next one.

Please visit our Python For Loop Learn more about loops in the tutorial.