Python Complex

A complex number is a number that consists of real and imaginary parts. For example, 2 + 3j is a complex number where 2 is the real component, and 3 multiplied by j is an imaginary part.

Example 1: Creating Complex and checking type

Python
num = 6 + 9j

print(type(num))

Output:

<class 'complex'>

Example 2: Performing arithmetic operations on complex type

Python
a = 1 + 5j
b = 2 + 3j

# Addition
c = a + b
print("Addition:",c)

d = 1 + 5j
e = 2 - 3j

# Subtraction
f = d - e
print("Subtraction:",f)


g = 1 + 5j
h = 2 + 3j

# Division
i = g / h
print("Division:",i)


j = 1 + 5j
k = 2 + 3j

# Multiplication
l = j * k
print("Multiplication:",l)

Output:

Addition: (3+8j)
Subtraction: (-1+8j)
Division: (1.307692307692308+0.5384615384615384j)
Multiplication: (-13+13j)

Python Numbers

In Python, “Numbers” is a category that encompasses different types of numeric data. Python supports various types of numbers, including integers, floating-point numbers, and complex numbers. Here’s a brief overview of each:

Table of Content

  • Python Integer
  • Python Float
  • Python Complex
  • Type Conversion in Python
  • Decimal Numbers in Python

Similar Reads

Python Integer

Python int is the whole number, including negative numbers but not fractions. In Python, there is no limit to how long an integer value can be....

Python Float

This is a real number with a floating-point representation. It is specified by a decimal point. Optionally, the character e or E followed by a positive or negative integer may be appended to specify scientific notation. . Some examples of numbers that are represented as floats are 0.5 and -7.823457....

Python Complex

A complex number is a number that consists of real and imaginary parts. For example, 2 + 3j is a complex number where 2 is the real component, and 3 multiplied by j is an imaginary part....

Type Conversion in Python

We can convert one number into the other form by two methods:...

Decimal Numbers in Python

Arithmetic operations on the floating number can give some unexpected results....