Python for Keyword

❮ Python Keywords


Example

Print each number from 1 to 8:

for x in range(1, 9):
  print(x)
Try it Yourself »

Definition and Usage

The for keyword is used to create a for loop.

It can be used to iterate through a sequence, like a list, tuple, etc.


More Examples

Example

Loop through all items in a list:

fruits = ["apple", "banana", "cherry"]

for x in fruits:
  print(x)
Try it Yourself »

Related Pages

Use the break keyword to break out of a loop.

Use the continue keyword to end the current iteration, but continue with the next.

Read more about for loops in our Python For Loops Tutorial.


❮ Python Keywords

Copyright 1999-2023 by Refsnes Data. All Rights Reserved.