terminology – What does it mean if a Python object is subscriptable or not?

terminology – What does it mean if a Python object is subscriptable or not?

terminology - What does it mean if a Python object is subscriptable or not

It basically means that the object implements the __getitem__() method. In other words, it describes objects that are containers, meaning they contain other objects. This includes strings, lists, tuples, and dictionaries.

Off the top of my head, the following are the only built-ins that are subscriptable:

string:  foobar[3] == b
tuple:   (1,2,3,4)[3] == 4
list:    [1,2,3,4][3] == 4
dict:    {a:1, b:2, c:3}[c] == 3

But mipadis answer is correct – any class that implements __getitem__ is subscriptable

terminology – What does it mean if a Python object is subscriptable or not?

A scriptable object is an object that records the operations done to it and it can store them as a script which can be replayed.

For example, see: Application Scripting Framework

Now, if Alistair didnt know what he asked and really meant subscriptable objects (as edited by others), then (as mipadi also answered) this is the correct one:

A subscriptable object is any object that implements the __getitem__ special method (think lists, dictionaries).

Leave a Reply

Your email address will not be published. Required fields are marked *