
上QQ阅读APP看书,第一时间看更新
4.4 complex类型
4.4.1 复数类型字面量
当数值字符串中包含虚部(j或J)时即复数字面量。Python解释器自动创建complex型对象实例。
【例4.8】 复数字面量示例。

4.4.2 complex对象
complex是Python的内置数据类型,用户可以创建complex类型的对象实例,其基本形式如下。

【例4.9】 complex对象示例。

4.4.3 complex对象的属性和方法
complex对象包含的属性和方法如表4-6所示。
表4-6 complex对象的属性和方法

在Python内部复数使用正交笛卡儿坐标表示,所以z==z.real+z.imag*1j。
4.4.4 复数的运算
复数对象支持算术运算、cmath模块中的数学运算函数、complex对象方法(参见4.4.3节)等运算操作。
在Python语言中,常用的complex数据类型对象的运算表达式如表4-7所示。
表4-7 Python常用的复数运算表达式

【例4.10】 复数运算示例。
