strange math?
joe.hrbek at gmail.com
joe.hrbek at gmail.com
Sun Mar 19 00:21:47 EST 2006
Hello everyone, I'm experimenting with python and i'm following this
tutorial:
http://docs.python.org/tut/node6.html#SECTION006400000000000000000 I'm
in section 4.7.5 Lambda Forms. In this section I was working along and
I noticed something strange. It happened because of a typo. Below is
a copy/paste from my idle session:
>>>def make_incrementor(n):
return lambda x: x+n
>>>f=make_incrementor(42)
>>>f(0)
42
>>>f(1)
43
>>>f(10)
52
>>>f(0)
42
>>>f(01)
43
>>>f(02)
44
>>>f(010)
50
>>>42+010
50
The first f(01) was a mistake. I accidentally forgot to delete the
zero, but to my suprise, it yielded the result I expected. So, I tried
it again, and viola, the right answer. So, I decided to really try and
throw it for a loop, f(010), and it produced 50. I expected 52
(42+10). Why doesn't python ignore the first zero and produce a result
of 52? It ignored the first zero for f(01) and f(02). Hmm. I know, I
know, why am I sending it a 01,02, or a 010 to begin with? Like I
said, it was an accident, but now i'm curious. I'm not a computer
science major so please be kind with any explanations.
More information about the Python-list
mailing list