溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Python中oct()函數(shù)的語法

發(fā)布時間:2020-11-16 09:20:06 來源:億速云 閱讀:455 作者:小新 欄目:編程語言

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

什么是oct函數(shù)?

oct()函數(shù)是Python3中的內置方法之一。 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ù)類型常量以外的任何內容作為參數(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ù)的語法的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注億速云行業(yè)資訊頻道!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經查實,將立刻刪除涉嫌侵權內容。

AI