Which types of objects fall into the domain of "subscriptable"?

Which types of objects fall into the domain of “subscriptable”?

Hello Anju,

The term “subscriptable” in Python describes objects that implement the __getitem__() method, making them capable of containing and providing access to other objects. This includes strings, lists, tuples, and dictionaries, among others.

Hope this helps clear your doubt.

Hey Dipen,

To add up to your answer, A “scriptable” object is one that can record the operations performed on it and store them as a “script” that can be replayed later. This concept is often seen in application scripting frameworks.

On the other hand, a “subscriptable” object, as mipadi mentioned, is any object that implements the __getitem__ special method. This includes objects like lists and dictionaries, which can be accessed using square brackets ([]) to retrieve items by index or key.

Hey Anju,

You can apply another approach as well, that is is for the gimme_things function to raise an exception when it cannot perform its intended action. While this may seem intimidating for beginners, it is a good practice to learn. It’s generally better to raise an exception and fail loudly than to return potentially incorrect information or an ambiguous result.

For instance, returning an empty list when no items are found could be misleading if the failure is due to a different issue. In such cases, raising an exception helps indicate the failure’s cause.

Hope this helps.