Python 数值类型


Python 中的数​​值类型是整数数据类型。它包括整数、浮点数、复数等。复数包括实部和虚部。也包括十六进制和八进制类型。

Python int 数据类型

数​​值类型包括 int 数据类型 −

a = 5 print("Integer = ",a) print("Type = ",type(a))

输出

Integer = 5
Type = <class 'int'>

Python float 数据类型

数​​值类型包括 float 数据类型 −

示例

a = 7E2 print("Float = ",a) print("Type = ",type(a))

输出

Float = 700.0
Type = <class 'float'>

Python complex 数据类型

数​​值类型包括具有实部和虚部的 complex 数据类型 −

示例

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'>

更新日期:2022-8-11

3K+ 浏览量

开启您的 职业生涯

完成课程,获得认证

开始吧
广告
© . All rights reserved.