# Python complex number example
# 创建一个复数
c = complex(3, 4)
print("复数 c:", c)
# 获取实部和虚部
real_part = c.real
imaginary_part = c.imag
print("实部:", real_part)
print("虚部:", imaginary_part)
# 复数的共轭
conjugate_c = c.conjugate()
print("c 的共轭:", conjugate_c)
# 复数的加法、减法、乘法和除法
d = complex(1, 2)
addition = c + d
subtraction = c - d
multiplication = c * d
division = c / d
print("c + d =", addition)
print("c - d =", subtraction)
print("c * d =", multiplication)
print("c / d =", division)
complex(3, 4) 创建了一个复数 3 + 4j。c.real 和 c.imag 分别获取复数的实部和虚部。c.conjugate() 返回复数的共轭,即 3 - 4j。上一篇:python pywin32
下一篇:python 键值对
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站