PYTHON FULL THEORY NOTES (STYLE C – Theory + Short Code + Tables)
UNIT 1 – INTRODUCTION TO PYTHON
Python vs Java:
- Python is interpreted, dynamically typed, concise; Java is compiled, statically typed, verbose.
- Python is used in AI/ML; Java in enterprise systems.
Python Interpreter & Environment:
- Interpreter executes code line-by-line (.py files).
- Environments: IDLE, VS Code, PyCharm, Jupyter.
Variables & Operators:
x = 10; y = 5
print(x+y, x-y)
Strings:
s = "Python"
print(s[0], s[1:4])
Conditionals & Loops:
if x>0: print("Positive")
for i in range(5): print(i)
Lists & Dictionaries:
lst = [1,2,3]
d = {"name": "A", "age": 20}
Functions (global, local, lambda):
x=10
def f(): y=5; print(x+y)
square = lambda n: n*n
-----------------------------------------------------
UNIT 2 – OOP, FILE HANDLING, EXCEPTIONS, MULTITHREADING
Classes & Objects:
class A: pass
obj = A()
Constructors & Destructors:
class Demo:
def __init__(self): print("Created")
def __del__(self): print("Destroyed")
Inheritance:
class A: pass
class B(A): pass
Modules & Packages:
import math
print([Link](25))
File I/O:
f=open("[Link]","w"); [Link]("Hello"); [Link]()
Exceptions:
try:
a=10/0
except ZeroDivisionError:
print("Error")
Multithreading:
import threading
def run(): print("Thread")
t=[Link](target=run)
[Link]()
Database Connectivity (MySQL):
import [Link]
con = [Link](host="localhost", user="root")
-----------------------------------------------------
UNIT 3 – NUMPY + VISUALIZATION
Creating Arrays:
import numpy as np
a=[Link]([1,2,3])
b=[Link]([[1,2],[3,4]])
Array Operations:
print(a+2, a*3)
Reshape:
[Link](3,1)
Concatenation:
[Link]([a,a])
Vectors & Matrices:
v=[Link]([1,2,3])
m=[Link]([[1,2],[3,4]])
Matplotlib Visualization:
import [Link] as plt
[Link]([1,2],[3,4]); [Link]()
Subplots:
fig,ax=[Link](1,2)
ax[0].plot([1,2],[3,4])
ax[1].bar([1,2],[5,6])
-----------------------------------------------------
UNIT 4 – PANDAS (DATA ANALYSIS)
Reading CSV, Excel, HDF5:
import pandas as pd
df=pd.read_csv("[Link]")
df2=pd.read_excel("[Link]")
df3=pd.read_hdf("file.h5")
Series & DataFrames:
s=[Link]([1,2,3])
df=[Link]({"A":[1,2],"B":[3,4]})
Grouping, Aggregating, Applying:
[Link]("A").agg(["sum","mean"])
df["A"].apply(lambda x:x+1)
Merging & Joining:
[Link](df1, df2, on="ID", how="inner")
[Link](df2)
(Time-series topics can be expanded as needed.)