Complete_Python_Notes_Basic_to_Advanced
Complete_Python_Notes_Basic_to_Advanced
1. Introduction to Python
Hello World:
print("Hello, World!")
Examples:
x=5
name = "Abhinav"
PI = 3.14159
3. Data Types
Type Conversion:
int("10"), float("5.5"), str(100), bool(0)
4. Operators
- Arithmetic: +, -, *, /, //, %, **
- Comparison: ==, !=, <, >, <=, >=
- Logical: and, or, not
- Membership: in, not in
- Identity: is, is not
5. Control Flow
Loops:
for i in range(5):
print(i)
Python Notes for Web/Backend Developer Interviews
Loop Controls:
- break, continue, pass
6. Functions
def greet(name="User"):
return f"Hello, {name}"
Arguments:
- Positional, Keyword, Default, *args, **kwargs
Lambda Function:
square = lambda x: x * x
7. Data Structures
List:
my_list = [1, 2, 3]
my_list.append(4)
Tuple:
my_tuple = (1, 2, 3)
Dictionary:
my_dict = {"name": "Abhinav", "age": 25}
Set:
my_set = {1, 2, 3}
8. Object-Oriented Programming
class Person:
def __init__(self, name):
self.name = name
def greet(self):
return f"Hi, I'm {self.name}"
9. File Handling
Writing:
with open('output.txt', 'w') as f:
f.write("Hello")
try:
x=1/0
except ZeroDivisionError as e:
print("Error:", e)
finally:
print("Done")
12. Comprehensions
List:
[x*x for x in range(10) if x % 2 == 0]
Dict:
{k: k*k for k in range(5)}
13. Decorators
def decorator(func):
def wrapper():
print("Before")
func()
print("After")
return wrapper
Python Notes for Web/Backend Developer Interviews
@decorator
def say_hello():
print("Hello")
def countdown(n):
while n > 0:
yield n
n -= 1
with open('file.txt') as f:
data = f.read()
17. Testing
import unittest
class TestMath(unittest.TestCase):
def test_add(self):
self.assertEqual(2 + 2, 4)
- Follow PEP8
- Use list comprehensions, unpacking, context managers
- Use meaningful variable/function names
Install Django:
pip install django
Start Project:
django-admin startproject myproject