Intro to Python Programming

study guides for every class

that actually explain what's on your next test

Range()

from class:

Intro to Python Programming

Definition

range() is a built-in Python function used to generate a sequence of numbers. It is commonly used in for loops to iterate over a series of values.

congrats on reading the definition of range(). now let's actually learn it.

ok, let's learn stuff

5 Must Know Facts For Your Next Test

  1. The range() function can take one, two, or three arguments.
  2. range(stop) generates numbers from 0 up to, but not including, stop.
  3. range(start, stop) generates numbers from start up to, but not including, stop.
  4. range(start, stop, step) generates numbers from start up to, but not including, stop, incrementing by step.
  5. The range() function returns an immutable sequence object of type 'range'.

Review Questions

  • How does the range() function differ when provided with one argument versus two?
  • What will be the output of list(range(1, 10, 2))?
  • Why might you use range() in a for loop?

"Range()" also found in:

Subjects (106)

© 2024 Fiveable Inc. All rights reserved.
AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.
Glossary
Guides