0
Can we make a range backeards like 20 to 5? (without using reverse)
5 Respuestas
+ 4
yes!
range(20, 5, -1)
+ 4
if you want 5 to be included do:
range(20, 4, -1)
+ 3
You can't write range(20, 5) because the standard value for step is 1, just like the standard value for start is 0. Each parameter you don't write is replaced by the standard parameter. range(5) is equal to range(0, 5, 1). range(2, 5) is equal to range(2, 5, 1). range(20, 5) is equal to range(20, 5, 1) and tells python to count upwards from 20 to 5 using steps of 1, which is impossible.
+ 1
oh now I understood thanks Anna
0
Ulisses Cruz but then why can't we just write range(20,5)? what's the problem just going from 20 to 4 like that and we need to use -1