How to judge a int number odd or even? (the binary way)
问题 I wanna use basic knowledge to improve the efficiency of code. I know that in binary system. when the last digit of number is 1,this is a odd number.and 0 is even number. How to use this way to judge a int number in python? Is that python give any build-in method to do it? 回答1: AND it with 1: 0000101001000101 0000000000000001 & __________________ 0000000000000001 If you get 1 , the number is odd. If you get 0 , the number is even. While this works, I would use the modulo operator instead: >>>