新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
創(chuàng)新互聯(lián)Python教程:Python中的oct() 函數(shù)是什么?
有小伙伴們對(duì)oct函數(shù)有了解的嗎?可能有小伙伴們反映說從來沒有見過的吧,更不知道是怎么要用,我們都知道語言是一個(gè)非常連貫的整體,任何一個(gè)環(huán)節(jié),我們不知道內(nèi)容,都可能造成下面的內(nèi)容不會(huì)銜接,所以對(duì)于生僻的內(nèi)容,我們一定要學(xué)會(huì)掌握,或者了解下,知道意思即可,好啦,不多說了,一起來看下吧~

什么是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
沒想到吧,就這簡(jiǎn)簡(jiǎn)單單三個(gè)字母的函數(shù),居然有這么強(qiáng)大的功能,多多掌握一些函數(shù)還是非常有益處的,關(guān)于這個(gè)函數(shù)還有無窮的使用技巧,大家先掌握部分,下部分內(nèi)容跟隨項(xiàng)目來學(xué)習(xí)吧~
文章題目:創(chuàng)新互聯(lián)Python教程:Python中的oct() 函數(shù)是什么?
當(dāng)前網(wǎng)址:http://m.fisionsoft.com.cn/article/coedche.html


咨詢
建站咨詢
