Python中oct()函數(shù)的語法-創(chuàng)新互聯(lián)

這篇文章主要介紹Python中oct()函數(shù)的語法,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!

成都創(chuàng)新互聯(lián)公司主要從事成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)揚(yáng)州,10多年網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):18982081108

什么是oct函數(shù)?

oct()函數(shù)是Python3中的內(nèi)置方法之一。 oct()方法采用整數(shù),并以字符串格式返回其八進(jìn)制表示形式。

oct()語法如下:

Syntax : oct(x) #語法
 
Parameters :   #參數(shù)
 
x – Must be an integer number and can be in either binary, decimal or hexadecimal format.
#  x必須為整數(shù),并且可以為二進(jìn)制,十進(jìn)制或十六進(jìn)制格式。
 
Returns : octal representation of the value.#返回值的八進(jìn)制表示形式。
 
Errors and Exceptions :   #錯(cuò)誤和異常:
TypeError : Returns TypeError when anything other than integer type constants are passed as parameters.
#TypeError:當(dāng)將整數(shù)類型常量以外的任何內(nèi)容作為參數(shù)傳遞時(shí),返回TypeError。

oct()函數(shù)的用法

print("The octal representation of 23 is " + oct(23))
print("The octal representation of the"
" ascii value of 'z' is " + oct(ord('z')))
print("The octal representation of the binary"
" of 23 is " + oct(0b10111))
print("The octal representation of the binary"
" of 23 is " + oct(0x17))

輸出:

The octal representation of 23 is 0o27
The octal representation of the ascii value of 'z' is 0o172
The octal representation of the binary of 23 is 0o27
The octal representation of the binary of 23 is 0o27

以上是Python中oct()函數(shù)的語法的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

網(wǎng)站欄目:Python中oct()函數(shù)的語法-創(chuàng)新互聯(lián)
網(wǎng)站路徑:http://muchs.cn/article6/pcdig.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站、網(wǎng)站排名、搜索引擎優(yōu)化、網(wǎng)站維護(hù)移動(dòng)網(wǎng)站建設(shè)、標(biāo)簽優(yōu)化

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

營銷型網(wǎng)站建設(shè)