1 A Number
1 A Number
Python provides built-in support for these number types, and we can perform arithmetic operations on them
easily.
1. Integer (int)
Represents whole numbers (positive, negative, or zero).
No decimal points allowed.
Can be of unlimited length (no size limit like in other languages).
🔹 Example:
python
CopyEdit
# Integer examples
a = 10 # Positive integer
b = -25 # Negative integer
c = 0 # Zero
2. Floating-Point (float)
Represents decimal numbers (positive or negative).
Can also be written using scientific notation (e or E for exponent).
🔹 Example:
python
CopyEdit
# Floating-point examples
x = 10.5 # Positive float
y = -3.14 # Negative float
z = 2.5e3 # Scientific notation (2.5 × 10³ = 2500.0)
🔹 Example:
python
CopyEdit
# Complex number examples
c1 = 3 + 4j # 3 is real, 4j is imaginary
c2 = -2.5 + 6j # -2.5 is real, 6j is imaginary
🔹 Example:
python
CopyEdit
# Arithmetic operations
a = 10
b = 3
print("Addition:", a + b) # Output: 13
print("Subtraction:", a - b) # Output: 7
print("Multiplication:", a * b) # Output: 30
print("Division:", a / b) # Output: 3.333...
print("Floor Division:", a // b) # Output: 3 (removes decimal part)
print("Modulus:", a % b) # Output: 1 (remainder)
print("Exponentiation:", a ** b) # Output: 1000 (10³)
🔹 Example:
python
CopyEdit
# Converting between types
num1 = 10 # Integer
num2 = 3.5 # Float
num3 = 4 + 2j # Complex
🔹 Example:
python
CopyEdit
a = 5
b = 2.5
c = 1 + 2j
python
CopyEdit
# Simple Calculator
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))