用法:
bin(x)
將整數轉換為前綴為“0b” 的二進製字符串。結果是一個有效的 Python 表達式。如果
x
不是 Pythonint
對象,則它必須定義一個返回整數的__index__()
方法。一些例子:>>> bin(3) '0b11' >>> bin(-10) '-0b1010'
如果需要或不需要前綴“0b”,您可以使用以下任一方式。
>>> format(14, '#b'), format(14, 'b') ('0b1110', '1110') >>> f'{14:#b}', f'{14:b}' ('0b1110', '1110')
另請參閱
format()
了解更多信息。
相關用法
- Python binascii.crc32用法及代碼示例
- Python binary轉string用法及代碼示例
- Python binary轉ASCII用法及代碼示例
- Python binascii.b2a_hex用法及代碼示例
- Python bin()用法及代碼示例
- Python bytes.isupper用法及代碼示例
- Python base64.b64decode()用法及代碼示例
- Python bokeh.plotting.figure.asterisk()用法及代碼示例
- Python bytes.zfill用法及代碼示例
- Python base64.b32decode()用法及代碼示例
- Python bytearray()用法及代碼示例
- Python bokeh.plotting.figure.annular_wedge()用法及代碼示例
- Python bool()用法及代碼示例
- Python bytes.isalpha用法及代碼示例
- Python base64.b85encode()用法及代碼示例
- Python bokeh.plotting.figure.circle()用法及代碼示例
- Python bytes.hex用法及代碼示例
- Python bz2.decompress(s)用法及代碼示例
- Python bokeh.plotting.figure.circle_cross()用法及代碼示例
- Python bokeh.plotting.figure.bezier()用法及代碼示例
注:本文由純淨天空篩選整理自python.org大神的英文原創作品 bin。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。