Python Notes - Beginner to Intermediate
Introduction to Python
Python is a high-level, interpreted programming language known for readability and simplicity. It is widely used in web
development, data science, AI, automation, and software development.
Variables and Data Types
Variables: Store data values.
Example:
x = 10
name = "Gaurav"
Common Data Types:
int, float, str, bool, list, tuple, set, dict
Input and Output
name = input("Enter your name: ")
print("Hello", name)
Operators
Arithmetic: +, -, *, /, %
Comparison: ==, !=, >,
Logical: and, or, not
Conditional Statements
if x > 0:
print("Positive")
elif x == 0:
print("Zero")
else:
print("Negative")
Loops
For Loop:
for i in range(5):
print(i)
While Loop:
count = 0
while count < 5:
print(count)
count += 1
Functions
def greet(name):
return "Hello " + name
Lists
nums = [1, 2, 3]
[Link](4)
print(nums[0])
Tuples
tup = (1, 2, 3)
Tuples are immutable.
Dictionaries
student = {"name": "Gaurav", "age": 21}
print(student["name"])
Object-Oriented Programming
class Person:
def __init__(self, name):
[Link] = name
Exception Handling
try:
x = 10 / 0
except ZeroDivisionError:
print("Cannot divide by zero")
File Handling
file = open("[Link]", "r")
print([Link]())
[Link]()
Modules
import math
print([Link](25))
Useful Python Libraries
NumPy - Numerical Computing
Pandas - Data Analysis
Matplotlib - Visualization
Flask/Django - Web Development
Tips for Beginners
1. Practice coding daily.
2. Learn problem solving.
3. Build small projects.
4. Read error messages carefully.