AI engineering glossary · Python advanced
What is __getitem__?
__getitem__: The special method that lets an object be indexed or sliced with square brackets. Defining it also makes the object iterable by position, which is how datasets in ML frameworks often expose their samples.
__getitem__: an example
def __getitem__(self, i): return self.data[i] lets you write ds[5] to fetch the sixth sample.
Related terms
More Python advanced terms
Where you learn it
__getitem__ is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.