Skip to content

Are there any problems with the rules of the assignment statement? #135269

Closed as not planned
@FallingSnowFlake

Description

@FallingSnowFlake

Documentation

the code is error

a = 1
b = 2
c = [111, 22]
a, b = *c  # Unpack operation is not allowed in this context

I don't understand why this a, b = *c statement is wrong?

about assigement expression doc link: https://docs.python.org/3.13/reference/simple_stmts.html#assignment-statements

we have the rules

assignment_stmt ::= (target_list "=")+ (starred_expression | yield_expression)
target_list     ::= target ("," target)* [","]
target          ::= identifier
                    | "(" [target_list] ")"
                    | "[" [target_list] "]"
                    | attributeref
                    | subscription
                    | slicing
                    | "*" target

the assignment_stmt RHS is a starred_expression

I'm still a beginner in python, Now I think the *c is a starred_expression

because

about starred_expression doc link: https://docs.python.org/3.13/reference/expressions.html#grammar-token-python-grammar-starred_expression

we have the rules:

starred_expression       ::= ["*"] or_expr

c Is a identifier
or_expr → xor_expr → and_expr → shift_expr → a_expr → m_expr → u_expr → power → primary → atom → identifier

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions