Hello everyone, I'm experimenting with python and i'm following this
tutorial:
http://docs.python.org/tut/node6.htm...00000000000000 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:
[color=blue][color=green][color=darkred]
>>>def make_incremento r(n):[/color][/color][/color]
return lambda x: x+n
[color=blue][color=green][color=darkred]
>>>f=make_incre mentor(42)
>>>f(0)[/color][/color][/color]
42[color=blue][color=green][color=darkred]
>>>f(1)[/color][/color][/color]
43[color=blue][color=green][color=darkred]
>>>f(10)[/color][/color][/color]
52[color=blue][color=green][color=darkred]
>>>f(0)[/color][/color][/color]
42[color=blue][color=green][color=darkred]
>>>f(01)[/color][/color][/color]
43[color=blue][color=green][color=darkred]
>>>f(02)[/color][/color][/color]
44[color=blue][color=green][color=darkred]
>>>f(010)[/color][/color][/color]
50[color=blue][color=green][color=darkred]
>>>42+010[/color][/color][/color]
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.
tutorial:
http://docs.python.org/tut/node6.htm...00000000000000 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:
[color=blue][color=green][color=darkred]
>>>def make_incremento r(n):[/color][/color][/color]
return lambda x: x+n
[color=blue][color=green][color=darkred]
>>>f=make_incre mentor(42)
>>>f(0)[/color][/color][/color]
42[color=blue][color=green][color=darkred]
>>>f(1)[/color][/color][/color]
43[color=blue][color=green][color=darkred]
>>>f(10)[/color][/color][/color]
52[color=blue][color=green][color=darkred]
>>>f(0)[/color][/color][/color]
42[color=blue][color=green][color=darkred]
>>>f(01)[/color][/color][/color]
43[color=blue][color=green][color=darkred]
>>>f(02)[/color][/color][/color]
44[color=blue][color=green][color=darkred]
>>>f(010)[/color][/color][/color]
50[color=blue][color=green][color=darkred]
>>>42+010[/color][/color][/color]
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.
Comment