詹惠儿

2019-01-17   阅读量: 524

数据分析师 Python编程

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
添加CDA认证专家【维克多阿涛】,微信号:【cdashijiazhuang】,提供数据分析指导及CDA考试秘籍。已助千人通过CDA数字化人才认证。欢迎交流,共同成长!
0.0000 0 0 关注作者 收藏

评论(0)


暂无数据

推荐课程

推荐帖子