> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Python complex

A built-in numeric data type in Python used to represent complex numbers, consisting of a real part and an imaginary part. Both components are stored internally as 64-bit IEEE 754 double-precision floating-point numbers (`float`).

## Instantiation

Complex numbers can be instantiated using literal syntax or the built-in `complex()` constructor. Python uses the suffix `j` or `J` to denote the imaginary unit (equivalent to *i* in mathematics).

```python theme={"dark"}

# Literal syntax
c1 = 4 + 3j
c2 = -2.5 + 1j
c3 = 5j          # Real part implicitly 0.0


# Constructor syntax: complex(real, imag)
c4 = complex(4, 3)
c5 = complex(-2.5, 1)
c6 = complex(0, 5)


# String parsing via constructor (no spaces allowed around the operator)
c7 = complex("4+3j")
```

## Attributes and Built-in Functions

The `complex` type exposes the real and imaginary components as read-only attributes, provides a built-in method for mathematical conjugation, and integrates with Python's standard `abs()` function to calculate the modulus.

```python theme={"dark"}
z = 3 + 4j


# Attributes return standard Python floats
real_part = z.real  # 3.0
imag_part = z.imag  # 4.0


# Returns a new complex object with the sign of the imaginary part reversed
conj = z.conjugate()  # (3-4j)


# The built-in abs() function returns the magnitude (modulus) as a float
magnitude = abs(z)  # 5.0
```

## Arithmetic Operations

Complex numbers support standard arithmetic operations, which follow standard algebraic rules for complex arithmetic.

```python theme={"dark"}
z1 = 2 + 3j
z2 = 1 - 1j

addition = z1 + z2       # (3+2j)
subtraction = z1 - z2    # (1+4j)
multiplication = z1 * z2 # (5+1j)
division = z1 / z2       # (-0.5+2.5j)
exponentiation = z1 ** 2 # (-5+12j)
```

## Type Constraints and Exceptions

Because the complex plane lacks a natural linear ordering, `complex` objects do not support relational comparison operators. Furthermore, operations that imply a scalar continuum or remainder logic are explicitly disabled.

```python theme={"dark"}
z1 = 2 + 3j
z2 = 4 + 1j


# Equality evaluation is supported
is_equal = (z1 == z2)  # False


# Relational comparisons raise TypeError

# z1 < z2  -> TypeError: '<' not supported between instances of 'complex' and 'complex'


# Floor division and modulo raise TypeError

# z1 // z2 -> TypeError: can't take floor of complex number.

# z1 % z2  -> TypeError: can't mod complex numbers.


# Explicit type casting to scalar types raises TypeError

# float(z1) -> TypeError: can't convert complex to float

# int(z1)   -> TypeError: can't convert complex to int
```

## Standard Library Integration

While the built-in `math` module only supports scalar floats and will raise a `TypeError` if passed a complex number, Python provides the `cmath` module specifically for complex mathematical functions.

```python theme={"dark"}
import cmath

z = 1 + 1j


# Calculate phase (argument)
phase = cmath.phase(z)  # 0.7853981633974483 (pi/4 radians)


# Convert to polar coordinates
polar = cmath.polar(z)  # Returns tuple: (1.4142135623730951, 0.7853981633974483)


# Convert from polar to rectangular
rect = cmath.rect(1.4142135623730951, 0.7853981633974483) # (1.0000000000000002+1j)
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Python Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
