Reputation: 5551
I am building up slice
s programatically for reasons, and would like to create a slice that grabs "everything". My immediate intuition was that
my_slice = slice()
would produce an object such that
assert (my_list[my_slice] == my_list) #True
However, a quick look at the docs reveals that slice
requires a stop
parameter.
Can I obtain an object all_slice
such that any_list[all_slice] == any_list
for all any_list
?
Upvotes: 5
Views: 649
Reputation: 61910
You can pass None
:
my_list = [1, 2, 3, 4]
my_slice = slice(None)
print(my_list[my_slice])
Output
[1, 2, 3, 4]
Upvotes: 12