🔢 Number Data Type
Last Updated: 11th August 2025
- In Python, numbers are used to store numeric values.
- They can be integers, floating-point numbers, or complex numbers.
- Numbers are immutable — you cannot change them after creation.
Hinglish Tip 🗣: Number ka matlab hai numeric value store karna, jaise 5, 3.14, ya 2+3j.
Types of Numbers
Python supports three main numeric types:
| Type | Example | Description |
|---|---|---|
| int | 10, -5 | Whole numbers without decimal |
| float | 3.14, -0.5 | Numbers with decimal point |
| complex | 2+3j | Numbers with real + imaginary part |
Examples:
# Integer
x = 10
# Float
y = 3.14
# Complex
z = 2 + 3j
print(x) # Output: 10
print(y) # Output: 3.14
print(z) # Output: (2+3j)
# Accessing real and imaginary parts
print(z.real) # Output: 2.0
print(z.imag) # Output: 3.0
# Type Checking
print(type(x)) # Output: <class 'int'>
print(type(y)) # Output: <class 'float'>
print(type(z)) # Output: <class 'complex'>
💡 Quick Practice
- Create an integer variable with value 15 and print its type.
- Exercise 4,5,6