On 2/22/18 11:00 AM, bartc wrote:
More importantly, "def x" is just a convenient way to express an
assignment to x. It behaves exactly like "x = make_a_function(name='x',
...)" (where I'm waving my hands about what happens in the ellipsis...
:) Just as there is no prohibition on "x = 1; x = 2", there's no
prohibition on "def x(); def x()"
On 22/02/2018 12:03, bartc wrote:
On the fib(20) test, it suggests using this to get a 30,000 times
BTW while doing my tests, I found you could redefine the same function
with no error:
For classes too. I was aware you could reassign a different value to
such names, but didn't know this applied to def.
I guess the reason is that 'def' is just another statement, and
statements can be conditional, so that you can have several versions.
Lots of Python statements are assignments to names, with precisely the
same referencing and scoping behaviors as conventional assignment. All
of these assign to x:
x = ...
import blah as x
from blah import x
for x in ...
with blah as x
except Something as x