1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > Python内置函数bin() oct()等实现进制转换

Python内置函数bin() oct()等实现进制转换

时间:2018-09-12 15:37:36

相关推荐

Python内置函数bin() oct()等实现进制转换

后端开发|Python教程

内置函数,进制,转换

后端开发-Python教程

使用Python内置函数:bin()、oct()、int()、hex()可实现进制转换。

先看Python官方文档中对这几个内置函数的描述:

bin(x)

Convert an integer number to a binary string. The result is a valid Python expression. If x is not a Python int object, it has to define an __index__() method that returns an integer.

oct(x)

Convert an integer number to an octal string. The result is a valid Python expression. If x is not a Python int object, it has to define an __index__() method that returns an integer.

int([number | string[, base]])

Convert a number or string to an integer. If no arguments are given, return 0. If a number is given, return number.__int__(). Conversion of floating point numbers to integers truncates towards zero. A string must be a base-radix integer literal optionally preceded by ‘+’ or ‘-‘ (with no space in between) and optionally surrounded by whitespace. A base-n literal consists of the digits 0 to n-1, with ‘a’ to ‘z’ (or ‘A’ to ‘Z’) having values 10 to 35. The default base is 10. The allowed values are 0 and 2-36. Base-2, -8, and -16 literals can be optionally prefixed with 0b/0B, 0o/0O, or 0x/0X, as with integer literals in code. Base 0 means to interpret exactly as a code literal, so that the actual base is 2, 8, 10, or 16, and so that int(‘010’, 0) is not legal, while int(‘010’) is, as well as int(‘010’, 8).

hex(x)

Convert an integer number to a hexadecimal string. The result is a valid Python expression. If x is not a Python int object, it has to define an __index__() method that returns an integer.

梦科技源码,ubuntu下mkl安装,浏览器测试tomcat,爬虫解析流程,php学习记录基础语法,seo前段lzw

bin()、oct()、hex()的返回值均为字符串,且分别带有0b、0o、0x前缀。

化妆品 源码,vscode 对比插件,ubuntu没有分区有什么影响,tomcat jmx实现,sqlite 外连接 异常,时间插件 时分秒,移动端h5前端框架框架,公众号爬虫公司排名,php 调用父类的方法,smo和seo,启点在线企业网站管理系统 v2.0,网页特效滚动字幕,百万盟建站模板,编写基于udp协议网络聊天程序lzw

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。