1. Complex Number & Argand Plane
z = a + bj
Real Component (
z.real):
3.14159
Imaginary Component (
z.imag):
2.71828
Drag or click anywhere on plane to steer z
Complex Repr
3.14159 + 2.71828j
z.real attribute
3.14159
z.imag attribute
2.71828j
abs(z) magnitude
4.1544
cmath.phase(z)
0.7130 rad
z.conjugate()
3.14159 - 2.71828j
# Python Interactive REPL
z = complex(3.14159, 2.71828)
print(z.real) # 3.14159
print(z.imag) # 2.71828
print(isinstance(z.real, float)) # True
2. Float Precision & Formatting
IEEE-754 / % / f-string
In Python, floating point real numbers have finite 64-bit precision. Select how you format z.real:
Formatted Output:
3.14
3. Pythonic Idiom Comparator
Zen of Python
Un-Pythonic Pattern Avoid
i = 0
for item in lines:
print(i, item)
i += 1
Pythonic Pattern Recommended
for i, item in enumerate(lines):
print(i, item)
Idiom Simulated Output:
0: line_one
1: line_two