Why is range(0) == range(2, 2, 2) True in Python 3?
问题 Why do ranges which are initialized with different values compare equal to one another in Python 3? When I execute the following commands in my interpreter: >>> r1 = range(0) >>> r2 = range(2, 2, 2) >>> r1 == r2 True The result is True . Why is this so? Why are two different range objects with different parameter values treated as equal? 回答1: The range objects are special: Python will compare range objects as Sequences . What that essentially means is that the comparison doesn't evaluate how