python oct

Python oct() function is used to convert an integer into octal string prefixed with “0o”.

Python oct()函数用于将整数转换为以“ 0o”为前缀的八进制字符串。

Python oct() (Python oct())

Python oct() function syntax is:

Python oct()函数语法为:

oct(x)

The output of oct() function is a string. We can pass an object as an argument too, in that case, the object must have __index__() function implementation that returns integer.

oct()函数的输出为string 。 我们也可以将对象作为参数传递,在这种情况下,该对象必须具有返回整数的__index__()函数实现。

Let’s look at some simple examples of oct() function.

让我们看一下oct()函数的一些简单示例。

print(oct(10))print(oct(0xF))print(oct(0b1111))print(type(oct(10)))

Output:

输出:

0o12
0o17
0o17
<class 'str'>

带有对象的Python oct() (Python oct() with object)

Let’s look at another example where we will use oct() function with a custom object as an argument. We will implement __index__() function in this object.

让我们看另一个示例,在该示例中我们将使用带有自定义对象作为参数的oct()函数。 我们将在此对象中实现__index __()函数。

class Data:id = 0def __init__(self, i):self.id = idef __index__(self):return self.idd = Data(20)print(oct(d))

Output: 0o24

输出: 0o24

GitHub Repository.GitHub存储库中检出完整的python脚本和更多Python示例。

Reference: Official Documentation

参考: 官方文档

翻译自: https://www.journaldev.com/22991/python-oct

python oct

python oct_Python oct()相关推荐

  1. [转载] python oct_Python oct()

    参考链接: Python oct() python oct Python oct() function is used to convert an integer into octal string ...

  2. Python字符串格式()

    Python String format() function is used to create a formatted string from the template string and th ...

  3. Python中的“ @”(@)符号有什么作用?

    我正在看一些使用@符号的Python代码,但我不知道它的作用. 我也不知道要搜索什么,因为搜索Python文档时会出现,或者当包含@符号时Google不会返回相关结果. #1楼 此代码段: def d ...

  4. 如何使用Python numpy.where()方法

    In Python, we can use the numpy.where() function to select elements from a numpy array, based on a c ...

  5. Python字符串title()

    Python String title() Python字符串title() Python String title() function returns a title cased version ...

  6. Python字符串isdecimal()

    Python String isdecimal() function returns True if all the characters in the string are decimal char ...

  7. Python字符串isalnum()

    Python string isalnum() function returns True if it's made of alphanumeric characters only. A charac ...

  8. Python字符串count()

    Python String count() function returns the number of occurrences of a substring in the given string. ...

  9. Python字符串splitlines()

    Python String splitlines() Python字符串splitlines() Python String splitlines() function returns the lis ...

最新文章

  1. WPF 4 日历控件(Calendar)
  2. 数据中心运维总监应具备哪些技能
  3. Hyperledger Fabric 核心模块(6)configtxlator工具
  4. 15拆分成3个不同的自然数_15个小时搜救破拆,他磨破3双手套营救出4个生还者...
  5. postgresql数据库基础
  6. 计算机能帮助我学英语翻译,英语翻译以下几个句子,帮忙把汉语翻译成英语,请不要用软件翻!1、计算机能帮助人们从事复杂的计算.几十年前可能需要数月完成...
  7. mysql where 大小写_java – 使用select where where Mysql在Mysql中区分大小写
  8. 对于大批量赋值功能,使用if判断是否能提高性能
  9. 线段树——I hate it
  10. JSP标签,jsp:include,jsp:forward用法介绍及示例
  11. 汽车租赁管理系统(管理车辆基本信息、租车/还车、统计租金)
  12. 【学习笔记】seckill-秒杀项目--(1)搭建项目
  13. VS2013+OpenCV2.4.10配置
  14. 安装旧版本Xcode——MACOS
  15. 关于DEP(数据执行保护)的分析
  16. mongodb数据库扩展名_MongoDB文件型数据库
  17. Scapy的介绍(一)
  18. 2022-07-10 第八小组 张明敏 学习笔记
  19. 人工智能VS人类智能,一个未知的矛盾对立理论
  20. Spider数据集arxiv1809.08887论文研读

热门文章

  1. Welcome-to-Swift-05控制流(Control Flow )
  2. RocketMQ3.2.6安装部署及调用
  3. selenium webdriver 学习总结-元素定位
  4. 注册flash.ocx inno setup (转)
  5. [转载] python字符串方法有哪些_27种Python字符串操作方法大全
  6. [转载] 【Python】不用numpy用纯python求极差、平均数、中位数、众数与方差,python的打印到控制台
  7. Spring MVC浅入浅出——不吹牛逼不装逼
  8. zabbix监控某个进程个数时产生的issue
  9. 让不同的库元件继承自共同的类
  10. python setattr 代码可读性_python __setattr__、__getattr__、__getattribute__全面详解