新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:Python bin()
bin 函數(shù)將整數(shù)作為輸入,并返回其等效的二進制字符串。

**bin(integer)** #where integer is an integer number
bin()參數(shù):
bin 函數(shù)只接受一個強制參數(shù),即一個整數(shù)。如果傳遞任何非整數(shù)參數(shù),該方法將引發(fā)類型錯誤。
| 參數(shù) | 描述 | 必需/可選 |
|---|---|---|
| 整數(shù) | 一個整數(shù),其二進制等價于要計算的 | 需要 |
bin()返回值
bin 函數(shù)返回一個二進制字符串。該二進制字符串是傳遞的整數(shù)參數(shù)的等效二進制
| 投入 | 輸出 | | 整數(shù) | 二進制串 |
Python 中bin()方法的示例
示例 1:在 Python 中將整數(shù)轉(zhuǎn)換為等效的二進制
int_num = 10
print('The binary equivalent of 10 is:', bin(int_num))
輸出:
The binary equivalent of 10 is: 0b1010
Here 0b indicates that its a binary number示例 2:傳遞非整數(shù)參數(shù)
int_num = 10.5
print('The binary equivalent of 10.5 is:', bin(int_num))
輸出:
TypeError: 'float' object cannot be interpreted as an integer 網(wǎng)站名稱:創(chuàng)新互聯(lián)Python教程:Python bin()
轉(zhuǎn)載源于:http://m.5511xx.com/article/dpoophd.html


咨詢
建站咨詢
