📜  liczby zespolone python 代码示例

📅  最后修改于: 2022-03-11 14:47:05.257000             🧑  作者: Mango

代码示例1
# complex number

x = -5.79829066331+4.55640490659j

# parts

r = x.real   # float
i = x.imag   # float

# tuple, not complex number

y = (x.real, x.imag)

# complex number again

a = complex(r, i)

b = r + i * 1j

# operations

c = a + b

d = a * b

e = 1j * 1j   # -1

f = abs(x)    # distance - float

g = x.conjugate()

import cmath  # not `math`

h = cmath.sin(x)

print('x:', x, type(x))
print('r:', r, type(r))
print('i:', i, type(i))
print('y:', y, type(y))
print('a:', a, type(a))
print('b:', b, type(b))
print('c:', c, type(c))
print('d:', d, type(d))
print('e:', e, type(e))
print('f:', f, type(f))
print('g:', g, type(g))
print('h:', h, type(h))
Copy To Clipboad