這篇文章主要介紹Python中oct()函數(shù)的語法,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!
什么是oct函數(shù)?
oct()函數(shù)是Python3中的內(nèi)置方法之一。 oct()方法采用整數(shù),并以字符串格式返回其八進制表示形式。
oct()語法如下:
Syntax : oct(x) #語法 Parameters : #參數(shù) x – Must be an integer number and can be in either binary, decimal or hexadecimal format. # x必須為整數(shù),并且可以為二進制,十進制或十六進制格式。 Returns : octal representation of the value.#返回值的八進制表示形式。 Errors and Exceptions : #錯誤和異常: TypeError : Returns TypeError when anything other than integer type constants are passed as parameters. #TypeError:當將整數(shù)類型常量以外的任何內(nèi)容作為參數(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)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
網(wǎng)站欄目:Python中oct()函數(shù)的語法-創(chuàng)新互聯(lián)
網(wǎng)站路徑:http://www.rwnh.cn/article6/pcdig.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站、網(wǎng)站排名、搜索引擎優(yōu)化、網(wǎng)站維護、移動網(wǎng)站建設、標簽優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)