+ 1

Python Range

Hello everyone. If I execute the code "print(range(20))" the list counts up to 19 . Why number "20" is not included?

12th Dec 2016, 3:51 AM
Joaquin Duval
Joaquin Duval - avatar
3 Réponses
+ 2
Well, the range() method starts with number 0, so if you count it from 0 to 19 is equal to 20. but if you want it to count from 1 to 20, just try using list(range(1,21))
12th Dec 2016, 6:25 AM
Giam Paolo
Giam Paolo - avatar
+ 2
What always messes me up is going back and forth between range() and random.randint() in a program. The arguments for randint follow the rules in your post. Always end up having to debug.
12th Dec 2016, 8:06 AM
Nick Bowling
Nick Bowling - avatar
0
Thanks a lot Giam Paolo.
12th Dec 2016, 4:28 PM
Joaquin Duval
Joaquin Duval - avatar