热线电话:13121318867

登录
2019-01-17 阅读量: 711
python的bin函数

python使用bin()可以减少编码所需的时间,还可以消除您在上述两种方法中看到的麻烦。

句法 : 
斗(A)
参数:
a:转换返回值的整数

整数或int对象的二进制字符串。
例外情况:
在参数中发送浮点值时引发TypeError。

# Python code to demonstrate working of

# bin()

# function returning binary string

def Binary(n):

s = bin(n)

# removing "0b" prefix

s1 = s[2:]

return s1

print("The binary representation of 100 (using bin()) is : ",end="")

print(Binary(100))

print("The binary representation of 100 (using bin()) is : ",end="")
print(Binary(100))

输出:

二进制表示100(使用bin())是:1100100
0.0000
0
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子