LoginSignup
21
18

More than 5 years have passed since last update.

Python で複素数を扱う

Posted at

Pythonista のみなさんは当然ご存知と思いますが、Python で普通に複素数を扱えることに感動したので・・・。

12 + 3j のように書くことで、複素数(Complex)を作ることができます。虚部には j をつけます。

実部と虚部を取り出すには、以下のように realimag を使います。

comp = 12 + 3j
print(comp.real)
# 12.0
print(comp.imag)
# 3.0

かけ算や割り算もばっちりです。

print((1 + 2j) * (3 + 4j))
# (-5+10j)
print((1 + 2j) / (3 + 4j))
# (0.44+0.08j))
21
18
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
21
18