- 1

Why print(range(0,100)[::-2] == range(99,0,-2)) prints true?

8th Apr 2018, 8:40 PM
Raunak Jalan
Raunak Jalan - avatar
3 Antworten
+ 8
Things get even more weird. In Python 3.2 that statement prints out False, while in Py3.6 - prints True. range(0, 100)[::-2] is range(99, -1, -2) and so for Python 3.2 it is different than range(99, 0, -2). Python 3.6 does not recognize this difference, as both ranges are equal, element-wise.
8th Apr 2018, 8:49 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 4
@ Kuba according to the documentation this is because: Changed in version 3.3: Define ‘==’ and ‘!=’ to compare range objects based on the sequence of values they define (instead of comparing based on object identity).
8th Apr 2018, 10:48 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
in 3.4 it is also True. it seems logical to return True, as both ranges return the same values
8th Apr 2018, 9:04 PM
Loïc Mahé
Loïc Mahé - avatar