Python 数字类型
programmingpythonserver side programming更新于 2025/3/14 14:36:17
Python 中的数字类型是整数数据类型。它包括整数、浮点数、复数等。复数包括实数和虚数部分。此外,还包括十六进制和八进制类型。
Python int 数据类型
数字类型包括 int 数据类型 −
a = 5 print("Integer = ",a) print("Type = ",type(a))
输出
Integer = 5 Type = <class 'int'>
Python 浮点数据类型
数字类型包括浮点数据类型 −
示例
a = 7E2 print("Float = ",a) print("Type = ",type(a))
输出
Float = 700.0 Type = <class 'float'>
Python 复杂数据类型
数字类型包括具有实值和虚值的复杂数据类型 −
示例
a = 2.75+3.15j print("Complex = ",a) print("Type = ",type(a))
输出
Complex = (2.75+3.15j) Type = <class 'complex'>
Python 十六进制类型
要表示八进制类型(基数为 16),请在前面添加 0x −
示例
a = 0x12 print("Hexadecimal = ",a) print("Type = ",type(a))
输出
Hexadecimal = 18 Type = <class 'int'>
Python 八进制类型
要表示八进制类型(基数为 8),请在前面添加 0(零)−
a = 0O20 print("Octal = ",a) print("Type = ",type(a))
输出
Octal = 16 Type = <class 'int'>
相关文章
有用资源
python 参考教程 - 该教程包含有关 python 的更多信息:https://www.cainiaomax.com/python/

