Slicing a list using a variable, in Python March 4, 2023 by Tarik that’s what slice() is for: a = range(10) s = slice(2,4) print a[s] That’s the same as using a[2:4].