Python 数值类型

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

Camera课程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

办公软件教程

Linux教程

计算机教程

大数据教程

开发工具教程