Handle complex numbers in Python

As you probably know only Pythonista, I was impressed by the fact that Python can handle complex numbers normally.

You can create a complex number (Complex) by writing like 12 + 3j. Add j to the imaginary part.

To retrieve the real and imaginary parts, use real and ʻimag` as follows:

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

Multiplication and division are perfect.

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

Recommended Posts

Handle complex numbers in Python
Handle markdown in python
Handle Parquet in Python
Prime numbers in Python
Handle Ambient data in Python
Handle environment variables in Python
Handle prime numbers in Python / Ruby / PHP / Golang (Go)
Testing with random numbers in Python
Handle posix message queues in python
Handle NetCDF format data in Python
Handle GDS II format in Python
How to handle Japanese in Python
Handle multiple python versions in one jupyter
Quadtree in Python --2
Python in optimization
CURL in python
Metaprogramming in Python
Python 3.3 in Anaconda
SendKeys in Python
Epoch in Python
Discord in Python
Sudoku in Python
DCI in Python
quicksort in python
nCr in python
N-Gram in Python
Programming in python
Constant in python
Lifegame in Python.
FizzBuzz in Python
Sqlite in python
StepAIC in Python
N-gram in python
I searched for prime numbers in python
LINE-Bot [0] in Python
Csv in python
Disassemble in Python
Reflection in Python
Constant in python
nCr in Python.
Scons in Python3
Puyo Puyo in python
python in virtualenv
PPAP in Python
Project Euler # 2 "Even Fibonacci Numbers" in Python
Quad-tree in Python
Reflection in Python
Chemistry in Python
DirectLiNGAM in Python
LiNGAM in Python
Flatten in python
flatten in python
Project Euler # 10 "sum of prime numbers" in Python
Use cryptography module to handle OpenSSL in Python
Handle zip files with Japanese filenames in Python 3
Project Euler # 13 "Sum of Large Numbers" in Python
Get files, functions, line numbers running in python
How to handle datetime type in python sqlite3
Sorted list in Python
Daily AtCoder # 36 in Python
Clustering text in Python