python中oct函数_Python中的oct()函数是什么?
有⼩伙伴们对oct函数有了解的吗?可能有⼩伙伴们反映说从来没有见过的吧,更不知道是怎么要⽤,我们都知道语⾔是⼀个⾮常连贯的整体,任何⼀个环节,我们不知道内容,都可能造成下⾯的内容不会衔接,所以对于⽣僻的内容,我们⼀定要学会掌握,或者了解下,知道意思即可,好啦,不多说了,⼀起来看下吧~
什么是oct函数?
oct()函数是Python3中的内置⽅法之⼀。 oct()⽅法采⽤整数,并以字符串格式返回其⼋进制表⽰形式。
oct()语法如下:Syntax : oct(x) #语法
Parameters :  #参数
x – Must be an integer number and can be in either binary, decimal or hexadecimal format.
#  x必须为整数,并且可以为⼆进制,⼗进制或⼗六进制格式。
Returns : octal representation of the value.#返回值的⼋进制表⽰形式。
Errors and Exceptions :  #错误和异常:
TypeError : Returns TypeError when anything other than integer type constants are passed as parameters.
#TypeError:当将整数类型常量以外的任何内容作为参数传递时,返回TypeError。
oct()函数的⽤法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
value函数什么意思
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
没想到吧,就这简简单单三个字母的函数,居然有这么强⼤的功能,多多掌握⼀些函数还是⾮常有益处的,关于这个函数还有⽆穷的使⽤技巧,⼤家先掌握部分,下部分内容跟随项⽬来学习吧~

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。