PYTHON
PROGRAMMING NOTES
Beginner Friendly Notes – Learn Python from Scratch, Step by Step
Every concept broken down with real working code, practice programs, an exam question bank and an MCQ set
with answers.
Concepts · Code Examples · Practice Programs · Exam Prep · MCQs
Page 1
, Python Programming Notes
Contents
1. What Is Python?
2. Variables
3. Data Types
4. Getting Input From the User
5. Operators
6. Making Decisions with if / elif / else
7. for Loops
8. while Loops
9. break and continue
10. Lists
11. Tuples
12. Sets
13. Dictionaries
14. Strings in More Detail
15. Functions
16. Scope (Where Your Variables Actually Live)
17. Exception Handling (Dealing With Errors Gracefully)
18. Modules
19. Object-Oriented Programming (Classes and Objects)
20. List Comprehension
21. File Handling
22. Mistakes Basically Everyone Makes at First
23. A Few Small Practice Programs
24. Quick Revision Sheet
25. Important Exam Questions
26. MCQs + Answer Key
Page 2
, Python Programming Notes
1. What Is Python?
Okay so before we jump into code, let's talk about what Python actually is. It's a programming language,
obviously, but what makes it different from something like Java or C++ is that it's really easy to read. Like, you
can look at a line of Python and kind of guess what it does even if you've never coded before. That's a big
reason it's so popular with beginners.
People use Python for basically everything now - building websites, automating boring tasks, doing data
analysis, machine learning, even game development. So learning it is genuinely useful, not just something
you're doing for a class and forgetting later.
▸ Your very first program
Every programming course starts the same way, and Python is no exception. We use the print() function to
show something on the screen.
print("Hello, world!")
That's it. Run this and Python will just show "Hello, world!" on your screen. Not exciting, but it's the tradition.
▸ Comments - notes for yourself
A comment is a line that Python completely ignores when it runs your code. You write comments to explain
what your code is doing, either for yourself later or for anyone else reading it. In Python you start a comment
with a # symbol.
# This line prints a greeting.
print("Hello, Python!")
Honestly, get into the habit of commenting your code early. Future-you will thank present-you when you come
back to a project after two months and have no idea what any of it does.
2. Variables
A variable is basically just a name you give to a piece of data so you can use it later without retyping it. Think of
it like a labeled box - you put something inside the box, and the label is how you find it again.
Page 3
, Python Programming Notes
The nice thing about Python compared to languages like Java is that you don't have to tell it what type of data
you're storing. You just assign a value and Python figures the rest out on its own.
name = "Ali"
age = 20
height = 5.8
print(name)
print(age)
print(height)
▸ You can change a variable whenever you want
Since Python doesn't lock a variable to a specific type or value, you can just reassign it later in your code and the
old value gets replaced.
score = 50
print(score)
score = 75
print(score)
Notice how score first prints 50, and after we give it a new value, it prints 75. The old value is basically gone
once you overwrite it.
3. Data Types
Even though Python doesn't force you to declare types, every value you use still has a type behind the scenes.
Knowing these types matters because they behave differently - you can add two numbers together, but you
can't "add" two words the same way (well, you can, but it does something different).
▸ Integer (int)
This is just a whole number - no decimal point.
age = 20
print(age)
print(type(age))
▸ Float
Page 4