Python Notes Summary
1. Dictionary Data Type
A dictionary is an unordered collection of key-value pairs. Keys must be unique and immutable.
Creating: my_dict = {"name": "Alice", "age": 25}
Accessing: my_dict["name"]
Modifying: my_dict["age"] = 26
Functions: len(), type(), str()
Methods: keys(), values(), items(), get(), pop(), clear()
2. Tuples and Sets
Tuples are ordered and immutable. Sets are unordered, mutable, and do not allow duplicates.
Tuples:
Creating: t = (1, 2, 3)
Indexing: t[0], Slicing: t[1:3]
Functions: len(), max(), min(), sum()
Sets:
Creating: s = {1, 2, 3}
Methods: add(), remove(), discard(), update(), union(), intersection(), difference()
Traversal: for i in s: print(i)
3. Strings
Strings are sequences of characters.
Creating: s = "Hello"
Accessing: s[0], Slicing: s[1:4]
Operations: +, *, in
Methods: lower(), upper(), strip(), replace(), split(), find()
Formatting: f"My name is {name}"
4. Files
Files can be text or binary.
Creating/Reading:
Write: open("[Link]", "w")
Read: open("[Link]", "r")
Modes: 'r', 'w', 'a', 'r+'
5. Python Libraries
NumPy: Array operations and numerical computing.
Pandas: Data manipulation with DataFrames.
Matplotlib: Data visualization (plots, graphs).
Python Notes Summary
Scikit-learn: Machine learning (model training, prediction).