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'>
广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP