Complete Python Learning Notes
Beginner to Intermediate • Study Guide + Practice
Python is a general-purpose programming language known for readable syntax and a large ecosystem.
This guide takes you from the basics through functions, collections, files, exceptions, modules,
object-oriented programming, and projects.
1. What is Python?
Python is a high-level programming language used for web development, automation, data analysis,
artificial intelligence, scripting, testing, and many other tasks. Its syntax is designed to be relatively easy to
read.
Example:
print("Hello, World!")
2. Installing Python
Install a current Python 3 release from the official Python website. After installation, verify it from a terminal
with:
python --version
On some systems the command may be python3 --version.
3. Your First Python Program
name = "Hassan"
print("Hello", name)
Python executes statements in order. Indentation is significant, so use consistent indentation—commonly
four spaces.
4. Variables
name = "Ali"
age = 20
price = 99.50
is_student = True
A variable refers to a value. Python determines the type at runtime, so you do not normally declare a
variable's type separately.
5. Data Types
name = "Ali" # str
age = 20 # int
price = 10.5 # float
active = True # bool
items = [1, 2, 3] # list
Common built-in types include str, int, float, bool, list, tuple, set, and dict.
6. Input and Output
name = input("Enter your name: ")
print("Welcome,", name)
input() returns text. Convert it when you need a number:
age = int(input("Enter age: "))
print(age + 1)
7. Operators
a = 10
b = 3
print(a + b)
print(a - b)
print(a * b)
print(a / b)
print(a // b)
print(a % b)
print(a ** b)
Comparison operators include ==, !=, >, <, >=, and <=. Logical operators include and, or, and not.
8. If / Elif / Else
age = 18
if age >= 18:
print("Adult")
elif age >= 13:
print("Teenager")
else:
print("Child")
Notice the indentation under each condition.
9. Loops
For loop:
for i in range(5):
print(i)
While loop:
count = 1
while count <= 5:
print(count)
count += 1
Useful loop controls include break to exit a loop and continue to skip to the next iteration.
10. Strings
text = "Python"
print([Link]())
print([Link]())
print(len(text))
print(text[0])
Modern Python code often uses f-strings for formatting:
name = "Ali"
age = 20
print(f"{name} is {age} years old.")
11. Lists
fruits = ["apple", "banana", "mango"]
[Link]("orange")
[Link]("banana")
print(fruits)
print(fruits[0])
Lists are ordered and mutable collections.
12. Tuples
coordinates = (10, 20)
print(coordinates[0])
Tuples are ordered collections that are generally used when the collection should not be changed.
13. Sets
numbers = {1, 2, 2, 3}
print(numbers)
Sets store unique elements and are useful for membership tests and set operations.
14. Dictionaries
student = {
"name": "Ali",
"age": 20,
"course": "Python"
}
print(student["name"])
student["age"] = 21
Dictionaries store key-value pairs.
15. Functions
def greet(name):
return f"Hello, {name}!"
message = greet("Ali")
print(message)
Functions help organize reusable logic. Learn parameters, return values, default arguments, and scope.
16. Lambda Functions
square = lambda x: x * x
print(square(5))
Lambda expressions are small anonymous functions. Use them when they make code clearer, not simply
because they are shorter.
17. List Comprehensions
squares = [x * x for x in range(6)]
print(squares)
Comprehensions provide a compact way to create collections.
18. Modules
import math
print([Link](25))
print([Link])
A module is a Python file or library that can provide reusable code. You can also import specific names:
from math import sqrt
print(sqrt(36))
19. Exceptions
try:
number = int(input("Number: "))
print(10 / number)
except ValueError:
print("Please enter a valid number.")
except ZeroDivisionError:
print("Cannot divide by zero.")
Exception handling lets programs respond to expected runtime errors instead of crashing without
explanation.
20. Files
with open("[Link]", "w", encoding="utf-8") as file:
[Link]("Hello Python")
with open("[Link]", "r", encoding="utf-8") as file:
content = [Link]()
print(content)
Using with is the recommended pattern because it manages the file resource automatically.
21. Object-Oriented Programming (OOP)
class Student:
def __init__(self, name, age):
[Link] = name
[Link] = age
def introduce(self):
return f"I am {[Link]}, age {[Link]}."
student = Student("Ali", 20)
print([Link]())
Important OOP concepts include classes, objects, attributes, methods, inheritance, encapsulation, and
polymorphism.
22. Virtual Environments and Packages
python -m venv .venv
# Windows
.venv\Scripts\activate
# macOS/Linux
source .venv/bin/activate
python -m pip install package_name
Virtual environments isolate project dependencies. Use pip to install packages from the Python package
ecosystem.
23. Debugging and Good Habits
Read error messages carefully. Check the line number, reproduce the problem with a small example, print
or inspect values, and change one thing at a time. Use meaningful variable names and keep functions
focused.
24. Recommended Learning Order
Python basics → variables and data types → operators → conditions → loops → strings →
lists/tuples/sets/dictionaries → functions → comprehensions → modules → exceptions → files → OOP →
packages/virtual environments → projects.
25. 30-Day Python Plan
Days 1–3: syntax, print, variables, input.
Days 4–6: data types and operators.
Days 7–9: if/elif/else.
Days 10–12: for and while loops.
Days 13–15: strings and lists.
Days 16–17: tuples, sets, dictionaries.
Days 18–20: functions and comprehensions.
Days 21–22: modules and exceptions.
Days 23–24: files.
Days 25–27: OOP.
Days 28–30: build and polish a final project.
26. Beginner Projects
1. Calculator
2. Number guessing game
3. To-do list
4. Unit converter
5. Quiz game
6. Contact book
7. Expense tracker
8. Password generator
9. File organizer
10. Simple text-based game
27. Intermediate Project Ideas
• Weather app using an API
• Web scraper
• Automation script
• CSV data analyzer
• Desktop utility
• Simple REST API
• Database-backed application
28. Final Cheat Sheet
print() output
input() user input
if/elif/else conditions
for/while loops
def function
return function result
list [] ordered mutable collection
tuple () ordered immutable collection
set {} unique collection
dict {} key-value collection
import use a module
try/except handle exceptions
open() work with files
class define a class
29. Best Way to Learn
Use roughly 30% theory and 70% hands-on practice. After learning each concept, write a small program
without copying the solution. Build projects as soon as possible and gradually make them more complex.
30. Official Documentation
Python documentation: [Link]
Python tutorial: [Link]
Python beginner resources: [Link]