Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära Range Function in Python | Loops in Python
Introduction to Python(ihor)

bookRange Function in Python

To iterate over indices instead of elements, use the range() function. It generates a sequence of numbers and returns a range object. The function accepts one, two, or three numeric arguments. With a single argument n, range(n) produces integers from 0 to n - 1. For example, range(5) generates 0 to 4.

123
# Range with one argument for i in range(5): print(i, end = ' ')
copy

With two arguments, range(n, m) generates integers from n to m - 1. For example, range(5, 10) produces 5 to 9.

123
# Range with two arguments for i in range(5, 10): print(i, end = ' ')
copy

With three arguments, range(n, m, s) generates numbers from n to m - 1, incrementing by s. For example, range(10, 30, 5) produces 10, 15, 20, 25.

123
# Range with three arguments for i in range(10, 30, 5): print(i, end = ' ')
copy
question mark

Which of the following range() functions will generate the sequence 2, 5, 8?

Select the correct answer

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 5. Kapitel 5

Fråga AI

expand

Fråga AI

ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

Awesome!

Completion rate improved to 1.67

bookRange Function in Python

Svep för att visa menyn

To iterate over indices instead of elements, use the range() function. It generates a sequence of numbers and returns a range object. The function accepts one, two, or three numeric arguments. With a single argument n, range(n) produces integers from 0 to n - 1. For example, range(5) generates 0 to 4.

123
# Range with one argument for i in range(5): print(i, end = ' ')
copy

With two arguments, range(n, m) generates integers from n to m - 1. For example, range(5, 10) produces 5 to 9.

123
# Range with two arguments for i in range(5, 10): print(i, end = ' ')
copy

With three arguments, range(n, m, s) generates numbers from n to m - 1, incrementing by s. For example, range(10, 30, 5) produces 10, 15, 20, 25.

123
# Range with three arguments for i in range(10, 30, 5): print(i, end = ' ')
copy
question mark

Which of the following range() functions will generate the sequence 2, 5, 8?

Select the correct answer

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 5. Kapitel 5
some-alt