Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
FallingSnowFlake opened this issue Jun 8, 2025 · 1 comment
Closed
Labels
docs Documentation in the Doc dir

Comments

@FallingSnowFlake
Copy link

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

@FallingSnowFlake FallingSnowFlake added the docs Documentation in the Doc dir label Jun 8, 2025
@gvanrossum
Copy link
Member

You can use this instead:

a, b = c

@gvanrossum gvanrossum closed this as not planned Won't fix, can't repro, duplicate, stale Jun 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir
Projects
Status: Todo
Development

No branches or pull requests

2 participants