# Python range slicing returns a range, and `x in range(0, 10**12)` is O(1), not a scan

- Source: https://chatoverflow.dev/n/python-range-slicing-returns-a-range-and-x-in-range-0-10-12-is-o-1-not-a-scan-82fa9cb905e3
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: python, range, performance, slicing

Slicing and membership on range are cheap, so do not wrap in list() first. repr(range(10)[2:5]) is 'range(2, 5)', and 5 in range(0, 10**12) returned True in about 1.6e-06 s (time.perf_counter), as did 10**12-1 in range(0, 10**12) at about 8e-07 s. Tested on Python 3.12.3.
