Tutorials References Paid Courses Log in
HTML CSS JAVASCRIPT SQL
Python range﴾﴿ Function
❮ Builtin Functions
Example
Create a sequence of numbers from 0 to 5, and print each item in the sequence:
x = range(6)
for n in x:
print(n)
Try it Yourself »
Definition and Usage
The range() function returns a sequence of numbers, starting from 0 by default, and
increments by 1 (by default), and stops before a specified number.
Syntax
range(start, stop, step)
Parameter Values
Parameter Description
start Optional. An integer number specifying at which position to start.
Default is 0
stop Required. An integer number specifying at which position to stop
(not included).
step Optional. An integer number specifying the incrementation. Default
is 1
More Examples
Example
Create a sequence of numbers from 3 to 5, and print each item in the sequence:
x = range(3, 6)
for n in x:
print(n)
Try it Yourself »
Example
Create a sequence of numbers from 3 to 19, but increment by 2 instead of 1:
x = range(3, 20, 2)
for n in x:
print(n)
Try it Yourself »
❮ Builtin Functions
NEW
We just launched
W3Schools videos
Explore now
COLOR PICKER
Get certified
by completing
a course today!
school
w3 s
1
02
CE
TI 2
R
FI .
ED
0
TI 2
R
FI .
ED
Get started
CODE GAME
Play Game
Report Error Forum About Shop
Top Tutorials Top References
HTML Tutorial HTML Reference
CSS Tutorial CSS Reference
JavaScript Tutorial JavaScript Reference
How To Tutorial SQL Reference
SQL Tutorial Python Reference
Python Tutorial W3.CSS Reference
W3.CSS Tutorial Bootstrap Reference
Bootstrap Tutorial PHP Reference
PHP Tutorial HTML Colors
Java Tutorial Java Reference
C++ Tutorial Angular Reference
jQuery Tutorial jQuery Reference
Top Examples Web Courses
HTML Examples HTML Course
HTML Examples HTML Course
CSS Examples CSS Course
JavaScript Examples JavaScript Course
How To Examples Front End Course
SQL Examples SQL Course
Python Examples Python Course
W3.CSS Examples PHP Course
Bootstrap Examples jQuery Course
PHP Examples Java Course
Java Examples C++ Course
XML Examples C# Course
jQuery Examples XML Course
Get Certified »
W3Schools is optimized for learning and training. Examples might be simplified to improve reading and
learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant
full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use,
cookie and privacy policy.
Copyright 19992021 by Refsnes Data. All Rights Reserved.
W3Schools is Powered by W3.CSS.