Python int转换为二进制字符串? [英] Python int to binary string?
本文介绍了Python int转换为二进制字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否存在任何固定的Python方法将Python中的Integer(或Long)转换为二进制字符串?
Are there any canned Python methods to convert an Integer (or Long) into a binary string in Python?
Google上有无数的dec2bin()函数.但是我希望可以使用内置函数/库.
There are a myriad of dec2bin() functions out on Google... But I was hoping I could use a built-in function / library.
推荐答案
Python的字符串格式方法可以采用格式规范.
Python's string format method can take a format spec.
>>> "{0:b}".format(37)
'100101'
这篇关于Python int转换为二进制字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文