Python Detailed Notes
1. Introduction to Python
- High-level, interpreted, and easy to learn.
- Dynamically typed, object-oriented.
- Portable, open-source, and has a large standard library.
2. Python Basics
Variables: x = 10, name = 'Alice'
Data Types: int, float, str, bool, list, tuple, set, dict
Type Casting: int('5'), str(10), float('3.14')
3. Operators
Arithmetic: + - * / // % **
Comparison: == != > < >= <=
Logical: and, or, not
Assignment: = += -=
Membership: in, not in
Identity: is, is not
4. Control Structures
If-else: if cond:
Loops: for i in range(), while cond
Loop Control: break, continue, pass
5. Functions
def greet(name):
return 'Hello ' + name
Lambda: square = lambda x: x**2
6. Data Structures
List: [1, 2, 3], .append()
Tuple: (1, 2)
Set: {1, 2, 3}
Dict: {'name': 'Rutu'}
7. String Operations
s = 'Python'
s.upper(), s[0:3], s.replace('P', 'J')
8. OOP in Python
class Car:
def __init__(self, brand):
self.brand = brand
def drive(self):
print(self.brand)
obj = Car('BMW')
9. Modules and Packages
import math
math.sqrt(25)
Custom: import mymodule
10. File Handling
with open('file.txt', 'r') as f:
print(f.read())
Modes: r, w, a, r+
11. Exception Handling
try:
x=1/0
except ZeroDivisionError:
print('Error')
finally:
print('Done')
12. Built-in Functions
len(), range(), type(), id(), sum(), max(), min(), input(), print()
13. Useful Libraries
Data: pandas, numpy
ML: sklearn, tensorflow
Web: flask, django
Auto: selenium, pyautogui
14. Python Environments
IDEs: VSCode, PyCharm
pip install package
Virtualenv: python -m venv env
15. Advanced Topics
Decorators, Generators, List Comprehensions, Regex, Threading, APIs, tkinter