+ 1
Trying range. isn't working
print(list(range(5,20,-2)))
6 odpowiedzi
+ 5
Joel Sebastian Jijo
Range means numbers between two values. So here 5 is min value and 20 is max value so range will return list of numbers between these two values.
Here 2 means list will be like 5, 7, 9, 11 but here is minus sign (-) so this range (5, 20, -2) will return empty list
So if you want in reverse order then do this print(list(range(20, 5, -2)))
Now here 20 will be considered as max value and 5 will be considered as min value so you will get list in reverse order.
+ 2
range function takes variable number of arguments.
When you pass one single argument, it is
range(end)
The start is default as 0 and the step is default as 1
When you passes two arguments, it is
range(start, end)
The step is default as 1.
When you passes three arguments, it i
range(start, end, step)
+ 1
Try
range(20,5,-2) or
range(5,20,2)
+ 1
From 20 to 5
Use range(20,4,-1)
0
I want to get the numbers backward.
0
Maybe it's my phone. all attempts to do backwards result in [ ].