forked from freeCodeCamp/wiki
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For issue 819 For issue 819 For issue 819 For issue 819
- Loading branch information
1 parent
9fb4569
commit 9752f28
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Python range(start, stop) | ||
|
||
Rather than being a function, range is actually an immutable sequence type and is commonly used for looping a specific number of times in for loops. | ||
`range(start, stop[, step])` is used in Python 3 to generate a sequence of type range from `start` till `stop` with increment of size `step`. | ||
|
||
## Arguments | ||
|
||
This function takes one argument, `start` or two arguments `start` and `stop` or three arguments `start`, `stop` and `step`. | ||
|
||
|
||
The value of the `start` parameter (or 0 if not provided) | ||
|
||
The value of the `stop` parameter (compulsory argument) | ||
|
||
The value of the `step` parameter (or 1 if not provided). It cannot be 0. | ||
|
||
All three must be of integer type. | ||
|
||
|
||
## Return | ||
|
||
If only `stop` is provided, it generates sequence of type range from `0` till `stop`. | ||
|
||
If both `start` and `stop` are provided, it generates sequence of type range from `start` till `stop`. | ||
|
||
If all three `start`, `stop` and `step` are provided, it generates sequence of type range from `start` till `stop` with increment of size `step`. | ||
|
||
|
||
|
||
## Example | ||
|
||
```python | ||
range(4) # returns range(0, 4) | ||
range(1,8) # returns range(1, 8) | ||
range(10,30,5) # returns range(10, 30, 5) | ||
``` | ||
:rocket: [Run Code](https://repl.it/CTIY/3) | ||
|
||
[Official Documentation](https://docs.python.org/3/library/functions.html#func-range) |