What does it mean if a Python object is “subscriptable” or not?

276    Asked by ranjan_6399 in Python , Asked on Apr 12, 2021

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

Answered by Ranjana Admin

In Python, the subscripting is nothing but indexing since it is the same as a mathematical notation that uses actual subscripts. In Python, for example, we use array[0] to get the first element of the array and the mathematicians use a0 for the same thing. In simple words, objects which can be subscripted are called sub scriptable objects. In Python, strings, lists, tuples, and dictionaries fall in subscriptable category.If we use array[0], python implements array.__getitem__(0) to subscript the array.

Note : subscriptable object is any object that implements the __getitem__ special method (think lists, dictionaries), used in a program, alone or with others, to specify one of the elements of an array."




Your Answer

Interviews

Parent Categories