Computer >> Computer tutorials >  >> Programming >> Python

What are the differences between list, sequence and slice data types in Python?


A list is a sequence but a sequence is not necessarily a list. A sequence is any type that supports the sequence interface ("protocol"). Sequence types describe a functional superset.

Slice objects are generally created implicitly via syntactic sugar (foo[2:5]) and provided to the container type special methods (such as __getitem__) which you can override. You will generally not have to deal with slices unless if you create your own sequences/containers.