user478514
user478514

Reputation: 4069

Why is 00100 = 64 in python?

Why, like in the following python code, does 00100 equal 64?

>>> i = 00100
>>> i
64
>>> type(00100)
<type 'int'>
>>> str(00100)
'64'
>>> str("00100")
'00100'
>>> int(str("00100"))
100
>>> 

Upvotes: 2

Views: 611

Answers (3)

genobis
genobis

Reputation: 1101

It's octal. http://en.wikipedia.org/wiki/Octal

1 is 01, 2 is 02, ..., 7 is 07, 8 is 10 (yes!), 9 is 011, etc.

Upvotes: 1

Terseus
Terseus

Reputation: 2212

In Python (and other languages too) when a number begin with 0 is interpreted as an octal number.

Upvotes: 2

n00b
n00b

Reputation: 5732

its an octal value because of leading zeros

http://www.translatorscafe.com/cafe/units-converter/numbers/calculator/octal-to-decimal/

^calculator (hard to summarize)

Upvotes: 9

Related Questions