Python 数值类型
Python 中的数值类型主要包括整数数据类型。其中包括整数、浮点数、复数等。复数类型包括实部和虚部。还包括十六进制和八进制类型。
Python 整数数据类型
数值类型包括整数数据类型:
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'>