Python Complete Professional Notes
1. Basics
Definition
Python is a high-level, interpreted, dynamically typed programming language.
Syntax
x = 10 # int
y = 3.14 # float
name = "Adarsh" # string
flag = True # boolean
Key Concepts
• Dynamic typing
• Variables store references to objects
2. Control Flow
Definition
Control flow determines the execution order of statements.
Syntax
if condition:
pass
elif condition:
pass
else:
pass
Loops
for i in range(5):
print(i)
while condition:
pass
1
3. Data Structures
List (Mutable)
arr = [1, 2, 3]
[Link](4)
Tuple (Immutable)
t = (1, 2, 3)
Set (Unique values)
s = {1, 2, 3}
Dictionary (Key-Value pairs)
d = {"key": "value"}
4. Strings
Syntax
text = "hello"
print(text[0])
print(text[::-1])
Formatting
name = "Adarsh"
print(f"Hello {name}")
5. Functions
Definition
Reusable block of code.
2
Syntax
def func(a, b):
return a + b
Advanced Parameters
def func(a, *args, **kwargs):
pass
6. Modules & Packages
import math
[Link](16)
Main Guard
if __name__ == "__main__":
pass
7. File Handling
with open("[Link]", "r") as f:
data = [Link]()
8. Exception Handling
try:
pass
except Exception:
pass
finally:
pass
3
9. OOP
Class Syntax
class A:
def __init__(self):
pass
Inheritance
class B(A):
pass
10. Iterators & Generators
it = iter([1,2,3])
next(it)
def gen():
yield 1
11. Decorators
def decorator(func):
def wrapper():
return func()
return wrapper
12. Context Managers
with open("[Link]") as f:
pass
4
13. Libraries
import os
import sys
import datetime
14. Regular Expressions
import re
[Link](r"\\d+", "123")
15. Memory Management
• Stack: function calls
• Heap: objects
• Garbage collection
16. Multithreading & Multiprocessing
import threading
import multiprocessing
17. Async Programming
async def main():
await func()
18. Advanced OOP
def __str__(self):
return "object"
5
19. Functional Programming
map(lambda x: x*x, [1,2,3])
20. Metaprogramming
type("ClassName", (), {})
21. Serialization
import json
[Link]({})
22. Testing
import unittest
23. Logging & Debugging
import logging
[Link]("msg")
24. Packaging
pip install package
25. Backend
• Django
• Flask
6
26. Database
SQL
SELECT * FROM table;
MongoDB
• NoSQL database