英文文档:
代码如下:
oct ( x )
Convert an integer number to an octal string. The result is a valid Python expression. If x is not a Pythonobject, it has to define anmethod that returns an integer.
说明:
1. 函数功能将一个整数转换成8进制字符串。如果传入浮点数或者字符串均会报错。
>>> a = oct(10)
>>> a
'0o12'
>>> type(a) # 返回结果类型是字符串
>>> oct(10.0) # 浮点数不能转换成8进制
Traceback (most recent call last):
File "", line 1, in
oct(10.0)
TypeError: 'float' object cannot be interpreted as an integer
>>> oct('10') # 字符串不能转换成8进制
Traceback (most recent call last):
File "", line 1, in
oct('10')
TypeError: 'str' object cannot be interpreted as an integer
2. 如果传入参数不是整数,则其必须是一个定义了__index__并返回整数函数的类的实例对象。
# 未定义