Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Power operation in Python [duplicate]

Tags:

python

I was playing around with Python. I had a doubt about the power operation in Python. So, I tried this:

0726**13 = 54609997061205831773270000000000000L 
726**13 = 15565965698792536237226936270158258176L

Why is there a difference between these two? I know it might be trivial. But, I could not figure it out. Could someone please explain? Thanks.

like image 434
karma_fanatic Avatar asked Mar 09 '26 15:03

karma_fanatic


1 Answers

It's because an integer constant beginning with 0 is taken to be an octal value. In this case, 0726 is interpreted as 470:

>>> 0726
470
>>> 470**13
54609997061205831773270000000000000L
>>> 
like image 67
Tom Karzes Avatar answered Mar 12 '26 05:03

Tom Karzes



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!