Immutable datatypes: int, float, string, tuple
Once these are created, their values cannot be altered in place. If you modify them, Python creates a new object in memory.int (Integer): Whole numbers without a decimal point.
- Example:
age = 25ortemperature = -5
float (Floating Point): Numbers that contain decimal points.
- Example:
price = 19.99orpi = 3.14159
str (String): Text wrapped in single, double, or triple quotes.
- Example:
name = "Python"
tuple (Tuple): An ordered, unchangeable collection of items. It allows duplicate values and is defined using parentheses.
- Example:
coordinates = (10.0, 20.0)
bool (Boolean): Represents one of two values: True or False.
Example: is_logged_in = True
Mutable datatypes: list, sets, dictionaries
These allow you to change, add, or delete elements after the data type has been created, without changing its memory identity.
list (List): An ordered, changeable collection of items that allows duplicate values. Defined using square brackets.
Example: shopping_list = ["apple", "banana", "cherry"]
set (Set): An unordered collection of unique items. Sets do not allow duplicate values and are defined using curly braces.
Example: unique_ids = {101, 102, 103}
dict (Dictionary): A collection of key-value pairs. They are ordered (as of Python 3.7+) and changeable, but do not allow duplicate keys. Defined using curly braces with colons.
Example: user_profile = {"username": "mishusco", "role": "admin"}
