BYU logo Computer Science

Dummy variables

Sometimes we may write a loop like this:

for number in range(5):
    print("Are we there yet?")

where the variable number isn’t used. We want to do something 5 times, but we don’t need to use number anywhere.

In cases like this, you can instead write:

for _ in range(5):
    print("Are we there yet?")

Here, the underscore represents a variable that isn’t used. You can use multiple underscores together, such as __ or ___ if you want.