Language Syntax

Annotated assignment — Python syntax

Attach an annotation to a simple name and optionally bind a value. In 3.13, module and class annotations normally evaluate eagerly unless postponed; function-local annotations are not evaluated or stored in the function annotation dictionary. An annotation does not enforce a type. Attribute or subscription targets can have annotations but do not populate the simple-name annotation mapping.

Formal Syntax & Structure

python syntaxpython
name: annotationname: annotation = expression

Parameters & Attributes

NameTypeDescription
nameassignment targetSimple name shown; attribute and subscription targets are also possible.
annotationexpressionAnnotation associated with the target.
expressionexpressionOptional initial value.

Working Example

Example Snippetpython
count: int = 'seven'print((__annotations__['count'] is int, count))
Python Reference