For the purposes of reading, all it's doing is setting a
and b
, so that a
= 0 and b
= 1. Similarly, in line 7, it's setting a
to b
and b
to the sum of a
and b
.
More specifically, it's setting tuples. Tuples are invariant, in that once they're created, their values can't change. Tuples are pervasive in python - you see them almost everywhere.
Typically, you would expect a tuple to be in parenthesis, e.g. (a, b) = (0, 1)
would read more cleanly, but they are such a large feature of python that the parenthesis are optional (unless you're constructing a tuple as an argument to a function, and then you need the extra parenthesis to differentiate between a single tuple and multiple arguments. I.e. you would have to say foo((a, b))
to pass a tuple to foo, as foo(a, b)
would pass two arguments to it.)
Tuples can be any length. You can write a, b, c, d, e = 0, 1, 2, 3, 4
, or you can have a function return a tuple, e.g.: ret1, ret2, ret3 = foobar(1)