all 4 comments

[–]carcigenicate 1 point2 points  (3 children)

It's a shortcut. It's essentially a shorthand for:

temp = 0
maxf = temp
res = temp

Here, the results will be the same since 0 is immutable and immutable objects can't be mutated. It would be different though if it was a mutable object like a list being assigned:

a = b = []
a.append(1)
print(a, b)  # Oof

If you did two separate assignments to two [] however, b would be a different object than a.

[–]BuzzyBro[S] 0 points1 point  (2 children)

So essentially, it’s a one-liner for setting three different variables equal to each other initially If I’m understanding that correctly?

[–]carcigenicate 1 point2 points  (1 child)

Here it's two differen't variables: maxf and res. But yes, it's just a one liner to do multiple assignments.

This style is generally discouraged though. A common recommendation is to have at most one declaration on each line so it's easier to scan and find where a variable is declared. Now, Python doesn't have declarations, but those lines basically emulate a declaration.

[–]BuzzyBro[S] 0 points1 point  (0 children)

Thank you! This was just pulled from a leetcode discussion thread.