Language Syntax
Subscription — Python syntax
Request an item through the subscription protocol. Comma-separated keys form a tuple; indexing may mean sequence access, mapping lookup or class subscription depending on the receiver.
Formal Syntax & Structure
python syntaxpython
object[key]Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| key | expression | Index, mapping key, or receiver-specific subscription key. |
Return Value
object
Value obtained by evaluating this expression; see description for context and constraints.
Working Example
Example Snippetpython
class Grid: def __getitem__(self,key): return keyprint(Grid()[1,2])