1

While using bitwise and operator (&) in my code I observed a strange behavior of python shell. While 10 and 10 gives 10 but 010 & 010 gives 8. These series follows for all the numbers with 0 in front like 011, 012, etc

Also, till 07 & 07 it works but 08 and 09 give a syntax error.

In python 3 we can't use 0 before a number altogether. Not able to understand is it an expected behavior or one of the python "wats".

Amit Tripathi
  • 7,003
  • 6
  • 32
  • 58

1 Answers1

2

Numbers entered with a leading zero are interpreted as octal (base 8).

007 == 7
010 == 8
011 == 9
Roman Skydan
  • 5,478
  • 4
  • 19
  • 39