Python Complete Notes
PYTHON NOTES — EASY DEFINITIONS + EASY CODES
UNIT 1
1. Operators
Definition:
Operators are symbols used to perform operations on values and variables.
Example:
a = 5
b = 2
print(a + b)
Types:
Arithmetic: + - * / % // **
Comparison: > < == !=
Logical: and or not
Operator Precedence:
Python follows BODMAS rules.
--------------------------------------------------
2. Type Conversion
Changing one data type into another.
Implicit Conversion:
a = 5
b = 2.5
print(a+b)
Explicit Conversion:
a = "10"
print(int(a))
--------------------------------------------------
3. Data Types
int → 5
float → 5.5
str → "Hello"
bool → True
list → [1,2]
tuple → (1,2)
set → {1,2}
dict → {"a":1}
UNIT 2
4. Conditional Statements
if:
if a > 5:
print("Big")
if-else:
if a > 5:
print("Big")
else:
print("Small")
elif:
if a > 0:
print("Positive")
elif a < 0:
print("Negative")
else:
print("Zero")
Nested if:
if a > 0:
if a % 2 == 0:
print("Even Positive")
--------------------------------------------------
5. Loops
for loop:
for i in range(5):
print(i)
while loop:
i = 1
while i <= 5:
print(i)
i += 1
Nested loop:
for i in range(3):
for j in range(3):
print(i, j)
--------------------------------------------------
6. break, continue, pass
break:
Stops loop completely.
continue:
Skips current iteration.
pass:
Temporary empty block.
UNIT 3
7. List
Ordered mutable collection.
a = [1,2,3]
[Link](4)
--------------------------------------------------
8. Tuple
Ordered immutable collection.
a = (1,2,3)
--------------------------------------------------
9. Set
Unique unordered collection.
a = {1,2,2,3}
--------------------------------------------------
10. String
Collection of characters.
name = "Yuvraj"
--------------------------------------------------
11. Dictionary
Stores data in key-value pair.
student = {
"name":"Yuvraj",
"age":18
}
--------------------------------------------------
12. Functions
def hello():
print("Hello")
hello()
Function with arguments:
def add(a,b):
print(a+b)
--------------------------------------------------
13. Mutable Sequence
Can be changed.
--------------------------------------------------
14. Unpacking Sequence
a,b,c = [1,2,3]
--------------------------------------------------
15. List Comprehension
a = [i for i in range(5)]
UNIT 4
16. File Handling
Write file:
f = open("[Link]","w")
[Link]("Hello")
[Link]()
Read file:
f = open("[Link]","r")
print([Link]())
--------------------------------------------------
17. Dynamic Typing
a = 5
a = "Hello"
--------------------------------------------------
18. Generators
def demo():
yield 1
yield 2
--------------------------------------------------
19. seek() Function
[Link](0)
UNIT 5
20. Python Packages
import math
--------------------------------------------------
21. Matplotlib
import [Link] as plt
--------------------------------------------------
22. NumPy
import numpy as np
--------------------------------------------------
23. Pandas
import pandas as pd
--------------------------------------------------
24. Tkinter
from tkinter import *
--------------------------------------------------
25. IDE & GUI
IDE:
VS Code, PyCharm
GUI:
Graphical User Interface
PROGRAMS
1. Fibonacci (Recursion)
def fib(n):
if n <= 1:
return n
return fib(n-1) + fib(n-2)
--------------------------------------------------
2. Leap Year
year = int(input())
if year % 4 == 0:
print("Leap Year")
--------------------------------------------------
3. Prime Number
n = int(input())
count = 0
for i in range(1,n+1):
if n % i == 0:
count += 1
if count == 2:
print("Prime")
--------------------------------------------------
4. Reverse String
a = input()
print(a[::-1])
--------------------------------------------------
5. Star Pattern
for i in range(5):
for j in range(i+1):
print("*", end="")
print()
--------------------------------------------------
6. LCM Program
a = int(input())
b = int(input())
--------------------------------------------------
7. Calculator
a = int(input())
b = int(input())
FASTEST WAY TO MEMORIZE PYTHON
1. Learn syntax patterns only
2. Practice 30 mins daily
3. Focus on loops + functions
4. Write code by hand
5. Understand logic first
MASTER MEMORY STRUCTURE
Input:
a = int(input())
If:
if condition:
code
Loop:
for i in range(n):
code
Function:
def name():
code