资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

Python中oct()函数的语法

这篇文章主要介绍Python中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
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()函数的语法的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联行业资讯频道!


当前名称:Python中oct()函数的语法
文章来源:http://cdkjz.cn/article/iiojoj.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220