Skip to content

tuple member access

dot-access tuple elements by position. expr.N where N is a non-negative integer lowers to expr[N]:

pair = (1, 2)
first = pair.0
second = pair.1

transpiles to:

pair = (1, 2)
first = pair[0]
second = pair[1]

works on any expression, not just name bindings. literal tuples need no parentheses beyond the tuple itself:

x = (1, 2).0

transpiles to:

x = (1, 2)[0]

chaining

multiple dot indices compose, and mix freely with regular attribute access, calls, and subscripts:

nested = (1, (2, 3)).1.0
attr   = pair.0.bit_length()
sliced = matrix.0[k]

transpiles to:

nested = (1, (2, 3))[1][0]
attr   = pair[0].bit_length()
sliced = matrix[0][k]

scope

expr.N is the only basedpython form of dot-indexing. negative indices, slices, and non-digit selectors fall through to ordinary attribute access and remain Expr.attr in the AST

see also