📊 Python Data Types — Mutable vs Immutable Table
Mutable /
Data Type Definition Exact Usage Example
Immutable
int ❌ Immutable Whole numbers without decimals Counting, age, scores → age = 25
Precise values like temperature →
float ❌ Immutable Decimal numbers
temp = 36.6
Numbers with real and imaginary
complex ❌ Immutable Scientific use → z = 2 + 3j
parts
bool ❌ Immutable Logical value: True or False Conditions, flags → is_valid = True
str ❌ Immutable Sequence of characters (text) Names, messages → name = "Ali"
Ordered collection of values, Fixed coordinates → location =
tuple ❌ Immutable
cannot be changed after creation (10, 20)
Secure, constant sets → fset =
frozenset ❌ Immutable Like a set, but unchangeable
frozenset({1, 2, 3})
Ordered collection, can be Shopping items → fruits =
list ✅ Mutable
changed ["apple", "banana"]
Unordered collection of unique Unique items → ids = {101, 102,
set ✅ Mutable
values 103}
User data → user = {"name": "Ali",
dict ✅ Mutable Key-value pairs (mapping)
"age": 25}
Sequence of bytes, can be Editing binary files → b =
bytearray ✅ Mutable
modified bytearray(b"hello")
Sequence of bytes, cannot be Binary data (read-only) → data =
bytes ❌ Immutable
changed b"hello"
View of a byte sequence (buffer), Low-level performance → mv =
memoryview ✅ Mutable
efficient memory use memoryview(b"abc")
#############)(#############
✅ Basic Python Functions & Methods for Beginners
📛 Name 💡 What It Does 🧱 Used With 🧪 Example Usage
print() Displays output on the screen All types print("Hello")
input() Takes user input All types name = input("Enter your name: ")
type() Shows the data type All types type(5) → <class 'int'>
len() Counts elements (length) str, list, dict len("Hi") → 2
int() Converts to integer All types int("5") → 5
float() Converts to float All types float("3.14") → 3.14
str() Converts to string All types str(10) → "10"
bool() Converts to boolean All types bool(0) → False
sum() Adds numbers in a list list sum([1, 2, 3]) → 6
min() / max() Finds smallest/largest list, str min([1, 2]) → 1
sorted() Returns a sorted list list, str sorted([3, 1, 2]) → [1, 2, 3]
range() Creates a range of numbers for loops range(5) → 0 1 2 3 4
📚 String (str) Methods – Use with "text"
📛 Name 💡 What It Does 🧪 Example Usage
.upper() Converts to UPPERCASE "hello".upper() → "HELLO"
.lower() Converts to lowercase "Hi".lower() → "hi"
.strip() Removes whitespace " hi ".strip() → "hi"
.replace() Replaces part of a string "hi".replace("h", "y") → "yi"
.split() Splits into a list by space/comma "a,b,c".split(",") → ['a', 'b', 'c']
.capitalize() Capitalizes the first letter "hello".capitalize() → "Hello"
🧾 List (list) Methods – Use with [1, 2, 3]
📛 Name 💡 What It Does 🧪 Example Usage
.append(x) Adds x to end of list my_list.append(4)
.insert(i, x) Adds x at index i my_list.insert(0, 99)
.pop() Removes last item my_list.pop()
.remove(x) Removes item x my_list.remove(2)
.sort() Sorts the list my_list.sort()
.reverse() Reverses the list my_list.reverse()
.count(x) Counts how many times x appears my_list.count(2)
📘 Dictionary (dict) Methods – Use with {"key": "value"}
📛 Name 💡 What It Does 🧪 Example Usage
.get(key) Gets value by key safely my_dict.get("name")
.keys() Returns list of keys my_dict.keys()
.values() Returns list of values my_dict.values()
.items() Returns key-value pairs my_dict.items()
.update() Adds or updates items my_dict.update({"age": 25})
.pop(key) Removes key and returns value my_dict.pop("age")
🧠 Bonus Utility Functions
📛 Name 💡 What It Does 🧪 Example Usage
list() Converts to list list("abc") → ['a', 'b', 'c']
dict() Creates a dictionary dict(name="Ali", age=20)
enumerate() Adds index while looping for i, val in enumerate(list):
zip() Combines multiple lists zip([1,2], ['a','b']) → [(1, 'a'), (2, 'b')]
✅ Tip for You as a Beginner:
Focus first on print(), input(), type(), len(), int(), str()
Then learn .upper(), .append(), .get()
Try writing small programs that ask input and show output with these.