Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not getting exact result in python with the values leading zero. Please tell me what is going on there

Tags:

python

zipcode = 02132

print zipcode

result = 1114

like image 292
himagiri Avatar asked Jun 18 '10 05:06

himagiri


2 Answers

A leading zero means octal. 2132 in octal equals 1114 in decimal. They removed this behavior in Python 3.0.

like image 120
Juri Robl Avatar answered Oct 06 '22 00:10

Juri Robl


In Python 2.x, number with a leading zero is interpreted as octal (base-eight). Python 3.x requires a leading "0o" to indicate an octal number. You probably want to treat a zipcode as a string to keep the leading zeroes intact.

like image 38
casevh Avatar answered Oct 06 '22 00:10

casevh