1.
Numeric Types:
int: Represents whole numbers.
Example: x = 5
float: Represents decimal numbers.
Example: y = 3.14
complex: Represents complex numbers with real and imaginary
parts.
Example: z = 2 + 3j
2. Boolean Type:
bool: Represents logical values, True or False.
Example: is_valid = True
3. Text Type:
str: Represents text data.
Example: greeting = "Hello"
4. Sequence Types:
list: A mutable sequence.
Example: fruits = ["Ramesh", "Mahesh", "Suresh"]
tuple: An immutable sequence.
Example: dimensions = (1920, 1080)
set: An unordered collection of unique items.
Example: nums = {1, 2, 3, 4}
5. Mapping Type:
dict: A collection of key-value pairs.
Example: person = {"name": "Ramesh", "age": 25}
1. Mutable Types
• Can be modified after creation.
• Examples:
list
dict
set
2. Immutable Types
• Cannot be modified after creation. Any operation that modifies an
immutable object creates a new object.
• Examples:
int: x = 5
x=x+1 (creates a new integer object)
float: pi = 3.14
tuple: t = (1, 2, 3)
str: name = "Ramesh"
name += "Das" (creates a new string object)
Aspect Mutable Immutable
Modification Can be changed in place Cannot be changed in place
Examples list, dict, set int, str, tuple, float
Performance Slower for certain operations Faster for read operations
Understanding the distinction helps in:
• Error prevention: Immutable types prevent unintended side-effects.
• Efficiency: Mutable types can save memory during updates.