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

NameTypeDescription
keyexpressionIndex, 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])
Python Reference