Verbose and flexible args and kwargs syntax
Chris Angelico
rosuav at gmail.com
Mon Dec 12 22:08:28 EST 2011
On Tue, Dec 13, 2011 at 1:43 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> It merely happens that C's
> use of the notation % for the remainder operation likely influenced
> Python's choice of the same notation.
Considering that Python also had the notion that "integer divided by
integer yields integer" until Py3, I would say it's extremely likely
that most of Python's division facilities were modelled off C. That's
not a bad thing; gives you a set of operations that a large number of
people will grok, and only a small number of oddities.
> I note that the *semantics* of the operation differs in the two
> languages, as I understand that the behaviour of % with negative
> arguments is left undefined by the C standard, while Python does specify
> the behaviour.
... and there's the proof that "modelled off" does not mean "slavishly
follows". This lack of definition is a weakness in C.
> def foo(a, 2*b+1, c): # double the second arg and add 1
No, that should subtract 1 from the second arg and halve it. The
expression you give there has to match the value from the parameter
list.
This syntax would be a huge boon to Python. Imagine how much easier
this could make things:
def foo(sum(x)):
return x
print(foo(120)) # will print a list of numbers that sum to 120
ChrisA
More information about the Python-list
mailing list