Skip to content

Remove Redundant Slice Index

Sourcery refactoring id: remove-redundant-slice-index

Description:

Removes unnecessary explicit 0 when slicing the beginning of a sequence.

Before:

With an end index:

numbers[0:5]

Without an end index:

numbers[0:]

After:

With an end index:

numbers[:5]

Without an end index:

numbers[:]

Explanation:

The default starting value for a slice is 0, so it is unnecessary to explicitly define it. This refactoring removes such zeros, slightly shortening the code.

Back to top