The range () function in Python
The range () function built into Python is used to create a sequence of numbers starting at 0 by default, incrementing 1 (by default) and ending at a specified number.
The range () function built into Python is used to create a sequence of numbers starting at 0 by default, incrementing 1 (by default) and ending at a specified number. Put simply, the function takes an integer and returns a range object (iterable).
In this article, TipsMake.com will learn about range (), syntax, parameters and examples with you. Invites you to read the track.
The syntax of the range () function in Python
The range () function in Python has two types of syntax:
range(stop)
range(start, stop[, step])
The parameters of the range () function
The range () function has 3 parameters:
start
: integer begins, the string will start with this parameter. The default value is 0.stop
: the integer ends, the string ends with this parameter.step
: integer specifies the distance between the numbers inside the string. The default value is 1.
Return value from range ()
1. With range (stop) syntax:
- Returns a string starting from 0 to
stop
-1. - Returns an empty string if the stop value is 0 or less than 0.
2. With range type syntax (start, stop [, step]):
- Without the
step
parameter, the defaultstep
will be 1: the return value is a string starting atstart
and ending atstop
-1 - If
step
equals 0, the exception exceptionValueError
will be raised. - If
step
, check if the parameters meet the constraint.- If yes, returns the string according to the formula, starting from
start
, the numbers separated bystep
, the last number of the string will be <stop
. - Otherwise returns an empty string.
- If yes, returns the string according to the formula, starting from
Example 1: how does range () work?
Update 25 November 2019
You should read it
- Max () function in Python
- The map () function in Python
- The function id () in Python
- The next () function in Python
- The ord () function in Python
- The function set () in Python
- The oct () function in Python
- The pow () function in Python
- Zip () function in Python
- Sum () function in Python
- Int () function in Python
- The slice () function in Python
Maybe you are interested
What does the 'super slow' 7680fps movie recording feature on the Mate 30 Pro do? Hitman Sniper famous game is being free on iOS and Android How to create slow motion videos on Android? 8 ways to win people's hearts 6 tips to help you get out of debt Changing these 10 ways of speaking will help you advance like 'windy kites'.