Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why isn't 0-padding allowed in Python?

Tags:

python

I've just noticed 0-padding is not allowed in Python and I was wondering why this choice was made?

For example:

a = 09

doesn't work while

a = 9

does

How's that?!

Thank you very much for your answers!

like image 733
ixM Avatar asked Mar 02 '26 22:03

ixM


1 Answers

Python, as many other languages, treat numbers starting with 0 as being in octal notation. 09 is not valid as octal

See chapter 2.4.4 in the python language reference.

like image 87
nos Avatar answered Mar 06 '26 09:03

nos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!