python刷题专用函数。。

无它,非bin()莫属。

bin(x)

Convert an integer number to a binary string. The result is a valid Python expression. If x is not a Python int object, it has to define an __index__() method that returns an integer.

bin函数返回一个二进制的字符串。对于无法用位运算,逻辑运算的python党们,这简直是利器阿!!!来吧!

>>> bin(9)
'0b1001'
>>> bin(-9)
'-0b1001'
>>> bin(-0)
'0b0'
>>> bin(0)
'0b0'
原文地址:https://www.cnblogs.com/Blaxon/p/4686216.html