strange math?
Ron Adam
rrr at ronadam.com
Sun Mar 19 06:53:11 CET 2006
joe.hrbek at gmail.com wrote:
>>>> 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.
Number beginning with the digit '0' are octal (base 8), so 010 == 8.
42 + 8 = 50.
Numbers beginning with '0x' are base 16.
Cheers,
Ron
More information about the Python-list
mailing list