On 2/21/2023 8:52 PM, Hen Hanna wrote:
On Tuesday, February 21, 2023 at 10:39:54 AM UTC-8, Thomas Passin wrote:
On 2/21/2023 12:32 PM, Axy via Python-list wrote:
On 21/02/2023 04:13, Hen Hanna wrote:
(A) print( max( * LisX ))
(B) print( sum( * LisX )) <------- Bad
syntax !!!
What's most surprising is.... (A) is ok, and (B) is not.
even tho' max() and sum() have (basically) the same
syntax... ( takes one arg , whch is a list )
They **don't** have basically the same signature, though. max() takes
either an iterable or two or more numbers. Using max(*list_) presents
it with a series of numbers, so that's OK.
sum() takes just one iterable (plus an optional start index). Using
sum(*list_) presents it with a series of numbers, and that does not
match its signature.
Check what I said:
help(sum)
Help on built-in function sum in module builtins:
sum(iterable, /, start=0)
help(max)
thakns... i like the use of the word [signature]
thanks for all the commetns... i'll try to catch up later.
i think i understand it much better now.
regular Python (func-calling) notation is like CL (Common Lisp) funcall.
and fun( * args ) notation is like a (compile-time) macro
( max( * X )) ----macroexpand---> (apply max X)
( max( * [1,2,3,4] )) ----macroexpand---> (apply max '(1 2
3 4) )
and
Max() can take many arguments, but
Sum() can basically take only 1.
... and that one has to be an iterable.
--
https://mail.python.org/mailman/listinfo/python-list