Python Complete Notes (A to Z) with Examples
1. Introduction to Python - Python is an interpreted, high-level, general-purpose programming
language. - Features: Simple, readable, dynamic typing, extensive libraries. - Install: From https://
[Link]/downloads/ - Run code: Using Python interpreter or IDE (PyCharm, VS Code).
Example:
print("Hello, Python!")
2. Basic Syntax - Variables: store data. - Data types: int, float, str, bool. - Comments: # for single line.
Example:
name = "Alice"
age = 20
print(name, age)
3. Operators - Arithmetic: + , - , * , / , % , ** , // - Assignment: = , += , -= - Comparison:
== , != , > , < , >= , <= - Logical: and , or , not
Example:
x = 10
y = 3
print(x + y, x ** y)
print(x > y and y < 5)
4. Conditional Statements
if x > y:
print("x is greater")
elif x == y:
print("x equals y")
else:
print("y is greater")
1
5. Loops
# For loop
for i in range(5):
print(i)
# While loop
count = 0
while count < 5:
print(count)
count += 1
6. Functions
def greet(name):
return f"Hello, {name}!"
print(greet("Alice"))
# Lambda function
square = lambda x: x**2
print(square(5))
7. Data Structures
# List
fruits = ["apple", "banana"]
[Link]("cherry")
# Tuple
coords = (10, 20)
# Set
unique = {1, 2, 3}
[Link](4)
# Dictionary
d = {"name": "Alice", "age": 20}
print(d["name"])
8. Strings
2
s = "Hello, World!"
print(s[0:5]) # Slice
print([Link]())
print(f"Name: {d['name']}")
9. Modules & Packages
import math
print([Link](16))
from random import randint
print(randint(1, 10))
10. File Handling
# Write file
with open("[Link]", "w") as f:
[Link]("Hello Python")
# Read file
with open("[Link]", "r") as f:
print([Link]())
11. Exception Handling
try:
num = int(input("Enter number: "))
except ValueError:
print("Invalid input")
finally:
print("End of program")
12. Object-Oriented Programming
class Person:
def __init__(self, name, age):
[Link] = name
[Link] = age
def greet(self):
3
print(f"Hi, I'm {[Link]}")
p = Person("Alice", 20)
[Link]()
13. Advanced Topics
# Decorator
def decorator(func):
def wrapper():
print("Before function")
func()
return wrapper
@decorator
def say_hello():
print("Hello")
say_hello()
# Generator
def gen():
for i in range(5):
yield i
for val in gen():
print(val)
14. Popular Libraries Overview
# NumPy
import numpy as np
arr = [Link]([1,2,3])
print(arr * 2)
# Pandas
import pandas as pd
df = [Link]({"A": [1,2], "B": [3,4]})
print(df)
# Matplotlib
import [Link] as plt
[Link]([1,2,3], [4,5,6])
[Link]()
4
End of Python Notes