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 = expressionParameters & Attributes
| Name | Type | Description |
|---|---|---|
| name | assignment target | Simple name shown; attribute and subscription targets are also possible. |
| annotation | expression | Annotation associated with the target. |
| expression | expression | Optional initial value. |
Working Example
Example Snippetpython
count: int = 'seven'print((__annotations__['count'] is int, count))