温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Python中oct()函数的语法

发布时间:2020-11-16 09:20:06 来源:亿速云 阅读:381 作者:小新 栏目:编程语言

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

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI