#1 Python tricks for Beginners
Using the Range() function
28 July, 2021
17
17
0
Contributors
🔨The Function: Range()
The range function creates a range of numbers on the fly for us. So we don't need to define a list before hand with a couple of numbers. The beauty of the function is that it's simple to use! Check it out👇
The range function takes 2 mandatory arguments and 1 optional.
Here's an example of the function with the generated object:
range(0,20,2)
[0,2,4,6,8,10,12,14,16,18]
Argument 1: '0'. This is the starting point of the range.
Argument 2: '20'. This is the end point of the range. NOTE, the number 20 will not be included in the range!
Argument 3: '2'. This is an optional argument. It will decide the 'steps'. So '2' adds 2 to every next generated number, starting at 0.
Let's check it out below
💻Code Snippet
python