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
num = 6 + 9j
print(type(num))
Output:
<class 'complex'>
Example 2: Performing arithmetic operations on complex type
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