I found both of them will output the expected result 2
.
max([a for a in [1,2]])
ismax()
+list comprehension
, an easy one.max(a for a in [1,2])
ismax()
+?
. Why does it work? What do we name the structurea for a in [1,2]
?
A generator is in form of (a for a in [1,2])
. I doubt that the (a for a in [1,2])
insides max(a for a in [1,2])
is a generator. However, if that's the case, why can a pair of ()
be ignored? Technically speaking it should be max((a for a in [1,2]))
.
Thanks.