Skip to content

Files

Latest commit

 

History

History
24 lines (16 loc) · 588 Bytes

invalid-slice-index.md

File metadata and controls

24 lines (16 loc) · 588 Bytes

Pattern: Invalid slice index

Issue: -

Description

Used when a slice index is not an integer, None, or an object with an __index__ method. This leads to unexpected behavior. Note that the slice numbers tell the start and stop positions for the slice in the list/tuple to get.

Example of incorrect code:

list = ['t', 'e', 's', 't']
print(list['t': 's'])

Example of correct code:

list = ['t', 'e', 's', 't']
print(list[0:3])

Further Reading