NUMBERS

Numbers are a fundamental data type used to represent numeric values.

There are three main types of numbers in Python:

1.int

2.float

3.complex

x=10   #int

y=5.6   #float

z=2j     #complex

Arithmetic operations on numbers.

Python supports various arithmetic operations on numbers:

# Addition

sum_result = 5 + 3

 

# Subtraction

difference_result = 7 - 2

 

# Multiplication

product_result = 4 * 6

 

# Division

quotient_result = 9 / 2  # Returns a float

 

# Floor Division (returns the quotient as an integer)

floor_result = 9 // 2

 

# Modulus (returns the remainder)

remainder_result = 9 % 2

 

# Exponentiation

power_result = 2 ** 3  # 2 raised to the power of 3

Type Conversion:

You can convert between different numeric types using functions like int(), float(), and complex().

# Convert float to int

int_value = int(3.14)

 

# Convert int to float

float_value = float(5)

 

# Convert int to complex

complex_value = complex(2)