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'

 

posted @ 2015-07-29 16:11  Xander-Hang  阅读(298)  评论(0编辑  收藏  举报