@本文来源于公众号:csdn2299,喜欢可以关注公众号 程序员学府
这篇文章主要介绍了使用Python内置函数:bin()、oct()、int()、hex()可实现进制转换的一些用法,需要的朋友可以参考下
使用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 anindex() 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 anindex() 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