What are assignment expressions (using the “walrus” or “:=” operator)? Why was this syntax added?

PEP 572 contains many of the details, especially for the first question. I’ll try to summarise/quote concisely arguably some of the most important parts of the PEP: Rationale Allowing this form of assignment within comprehensions, such as list comprehensions, and lambda functions where traditional assignments are forbidden. This can also facilitate interactive debugging without the … Read more

“:=” syntax and assignment expressions: what and why?

PEP 572 contains many of the details, especially for the first question. I’ll try to summarise/quote concisely arguably some of the most important parts of the PEP: Rationale Allowing this form of assignment within comprehensions, such as list comprehensions, and lambda functions where traditional assignments are forbidden. This can also facilitate interactive debugging without the … Read more