Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Range() in a for Loop 1/2 | The for Loop
Python Loops Tutorial
course content

Contenido del Curso

Python Loops Tutorial

Python Loops Tutorial

1. The for Loop
2. The while Loop
3. Nested Loops

Range() in a for Loop 1/2

Imagine that we wish to print numbers from 1 to 100. Naturally, we could do this manually:

But that would be incredibly time-consuming!

If we had to print numbers from 1 to 1,000,000, we'd be counting manually for the rest of our lives!

To tackle this challenge, we'll employ the for loop in conjunction with the range() function!

Take a look at the following code:

123
# Printing all numbers from 0 to 100 for i in range(101): print(i)
copy

How does the code work?

The range() function provides a sequence of numbers that starts at 0 (by default) when the initial limit is unspecified. It increments by 1 (by default) until it reaches a final limit (the final limit itself is not included).

The format of the range() function is: range(start, end, step).

If our intention is to operate with decreasing numbers, we can achieve this by inputting a negative step argument into the range() function.

Look at the code below:

123456789
# Increasing # Printing numbers from 0 to 10 for i in range(0, 11, 1): print(i) # Decreasing # Printing numbers from 10 to 0 for i in range(10, -1, -1): print(i)
copy

Tarea

Print numbers from -1 to -5, follow these steps:

  1. Configure the for loop to display decreasing numbers from -1 to -5.
  2. Print each number within the loop.

Tarea

Print numbers from -1 to -5, follow these steps:

  1. Configure the for loop to display decreasing numbers from -1 to -5.
  2. Print each number within the loop.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

Sección 1. Capítulo 2
toggle bottom row

Range() in a for Loop 1/2

Imagine that we wish to print numbers from 1 to 100. Naturally, we could do this manually:

But that would be incredibly time-consuming!

If we had to print numbers from 1 to 1,000,000, we'd be counting manually for the rest of our lives!

To tackle this challenge, we'll employ the for loop in conjunction with the range() function!

Take a look at the following code:

123
# Printing all numbers from 0 to 100 for i in range(101): print(i)
copy

How does the code work?

The range() function provides a sequence of numbers that starts at 0 (by default) when the initial limit is unspecified. It increments by 1 (by default) until it reaches a final limit (the final limit itself is not included).

The format of the range() function is: range(start, end, step).

If our intention is to operate with decreasing numbers, we can achieve this by inputting a negative step argument into the range() function.

Look at the code below:

123456789
# Increasing # Printing numbers from 0 to 10 for i in range(0, 11, 1): print(i) # Decreasing # Printing numbers from 10 to 0 for i in range(10, -1, -1): print(i)
copy

Tarea

Print numbers from -1 to -5, follow these steps:

  1. Configure the for loop to display decreasing numbers from -1 to -5.
  2. Print each number within the loop.

Tarea

Print numbers from -1 to -5, follow these steps:

  1. Configure the for loop to display decreasing numbers from -1 to -5.
  2. Print each number within the loop.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

Sección 1. Capítulo 2
toggle bottom row

Range() in a for Loop 1/2

Imagine that we wish to print numbers from 1 to 100. Naturally, we could do this manually:

But that would be incredibly time-consuming!

If we had to print numbers from 1 to 1,000,000, we'd be counting manually for the rest of our lives!

To tackle this challenge, we'll employ the for loop in conjunction with the range() function!

Take a look at the following code:

123
# Printing all numbers from 0 to 100 for i in range(101): print(i)
copy

How does the code work?

The range() function provides a sequence of numbers that starts at 0 (by default) when the initial limit is unspecified. It increments by 1 (by default) until it reaches a final limit (the final limit itself is not included).

The format of the range() function is: range(start, end, step).

If our intention is to operate with decreasing numbers, we can achieve this by inputting a negative step argument into the range() function.

Look at the code below:

123456789
# Increasing # Printing numbers from 0 to 10 for i in range(0, 11, 1): print(i) # Decreasing # Printing numbers from 10 to 0 for i in range(10, -1, -1): print(i)
copy

Tarea

Print numbers from -1 to -5, follow these steps:

  1. Configure the for loop to display decreasing numbers from -1 to -5.
  2. Print each number within the loop.

Tarea

Print numbers from -1 to -5, follow these steps:

  1. Configure the for loop to display decreasing numbers from -1 to -5.
  2. Print each number within the loop.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

Imagine that we wish to print numbers from 1 to 100. Naturally, we could do this manually:

But that would be incredibly time-consuming!

If we had to print numbers from 1 to 1,000,000, we'd be counting manually for the rest of our lives!

To tackle this challenge, we'll employ the for loop in conjunction with the range() function!

Take a look at the following code:

123
# Printing all numbers from 0 to 100 for i in range(101): print(i)
copy

How does the code work?

The range() function provides a sequence of numbers that starts at 0 (by default) when the initial limit is unspecified. It increments by 1 (by default) until it reaches a final limit (the final limit itself is not included).

The format of the range() function is: range(start, end, step).

If our intention is to operate with decreasing numbers, we can achieve this by inputting a negative step argument into the range() function.

Look at the code below:

123456789
# Increasing # Printing numbers from 0 to 10 for i in range(0, 11, 1): print(i) # Decreasing # Printing numbers from 10 to 0 for i in range(10, -1, -1): print(i)
copy

Tarea

Print numbers from -1 to -5, follow these steps:

  1. Configure the for loop to display decreasing numbers from -1 to -5.
  2. Print each number within the loop.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
Sección 1. Capítulo 2
Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
We're sorry to hear that something went wrong. What happened?
some-alt