How does python “know” what to do with the “in” keyword?

According to the for compound statement documentation:

Each item in turn is assigned to the target list using the standard
rules for assignments…

Those “standard rules” are in the assignment statement documentation, specifically:

Assignment of an object to a target list is recursively defined as
follows.

  • If the target list is a single target: The object is assigned to that target.

  • If the target list is a comma-separated list of targets: The object must be an iterable with the same number of items as there are targets
    in the target list, and the items are assigned, from left to right, to
    the corresponding targets.

So this different behaviour, depending on whether you assign to a single target or a list of targets, is baked right into Python’s fundamentals, and applies wherever assignment is used.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)