Python Notes
Python Notes
Readable notes for syntax, data structures, functions, files, and modules
These notes are designed for quick revision, beginner-friendly explanation, and practical programming or
database study. Each section includes key ideas and a small checklist so the document can be used for
class preparation, interview revision, or project practice.
How to use this document: read a section, type or write a small example, test yourself with the checklist, and
then revise the topic after one or two days.
Contents
1. 1. What Python Is
2. 2. Variables and Data Types
3. 3. Input, Output, and Formatting
4. 4. Operators and Conditions
5. 5. Loops
6. 6. Lists, Tuples, Sets, and Dictionaries
7. 7. Functions
8. 8. Strings and Files
9. 9. Modules and Packages
10. 10. Object-Oriented Programming
11. 11. Exceptions and Debugging
12. 12. Revision Checklist and Practice Plan
Page 1
Python Notes
1. What Python Is
Python is a high-level, interpreted programming language known for readable syntax and fast development.
It is used in education, automation, data analysis, web development, machine learning, scripting, and
testing.
Python programs are usually written in .py files and executed by the Python interpreter. In notebooks such
as Jupyter, code is run in cells, which is useful for experiments and learning.
Python uses indentation to define blocks. This is different from languages that use braces. Good indentation
is not only style; it is required for correct execution.
Key points
Interpreted language
Readable syntax
Indentation defines blocks
Popular for data analysis and automation
Study task
Write a small example or explanation for this topic. Then identify one common error related to what python is
and describe how to fix it. This habit strengthens practical understanding and helps in exams, labs, and
interviews.
Page 2
Python Notes
2. Variables and Data Types
Python variables are created when values are assigned. A variable does not need an explicit type
declaration. The type belongs to the value, not the variable name.
Common types include int, float, bool, str, list, tuple, dict, set, and NoneType. Python automatically handles
large integers, which makes arithmetic convenient.
Even though Python is dynamically typed, type awareness is still important. Mixing strings and numbers
incorrectly can cause TypeError. Use type conversion functions such as int, float, and str when needed.
Key points
int whole numbers
float decimals
str text
bool true or false
None means no value
Study task
Write a small example or explanation for this topic. Then identify one common error related to variables and
data types and describe how to fix it. This habit strengthens practical understanding and helps in exams,
labs, and interviews.
Page 3
Python Notes
3. Input, Output, and Formatting
The input function reads text from the user. Because input always returns a string, numeric input must be
converted using int or float before arithmetic.
The print function displays output. Multiple values can be printed with commas. Formatted strings, called f-
strings, are a clear way to combine variables and text.
For decimal formatting, f-strings can specify places, such as displaying a value to two decimal places. This
is useful for money, percentages, and measurements.
Key points
input returns string
print displays output
f-strings format text
Use :.2f for two decimals
Study task
Write a small example or explanation for this topic. Then identify one common error related to input, output,
and formatting and describe how to fix it. This habit strengthens practical understanding and helps in exams,
labs, and interviews.
Page 4
Python Notes
4. Operators and Conditions
Python supports arithmetic operators +, -, *, /, //, %, and **. The / operator performs true division. The //
operator performs floor division. The ** operator is used for powers.
Comparison operators include ==, !=, <, <=, >, and >=. Logical operators are written as and, or, and not.
This makes Python conditions easy to read.
The if, elif, and else statements are used for decisions. Each condition line ends with a colon, and the
indented block below it runs when the condition is true.
Key points
** means power
// means floor division
and combines conditions
or allows alternatives
not reverses condition
Study task
Write a small example or explanation for this topic. Then identify one common error related to operators and
conditions and describe how to fix it. This habit strengthens practical understanding and helps in exams,
labs, and interviews.
Page 5
Python Notes
5. Loops
Python has for loops and while loops. A for loop is commonly used to iterate over a range, list, string,
dictionary, or file. A while loop repeats as long as a condition remains true.
The range function generates a sequence of numbers. range(5) gives 0 through 4. range(1, 6) gives 1
through 5. range can also use a step value.
Loop tools include break to exit early and continue to skip to the next iteration. Use these carefully so the
loop remains easy to understand.
Key points
for iterates over items
while repeats by condition
range creates number sequence
break exits loop
continue skips one round
Study task
Write a small example or explanation for this topic. Then identify one common error related to loops and
describe how to fix it. This habit strengthens practical understanding and helps in exams, labs, and
interviews.
Page 6
Python Notes
6. Lists, Tuples, Sets, and Dictionaries
A list is an ordered, changeable collection. Lists are used for sequences of values such as marks, names,
prices, or tasks. Common methods include append, remove, sort, and pop.
A tuple is ordered but not changeable. It is useful for fixed records such as coordinates. A set stores unique
values and is useful for removing duplicates or checking membership quickly.
A dictionary stores key-value pairs. It is useful when each item has a label, such as student names mapped
to marks or product codes mapped to prices.
Key points
list is mutable
tuple is immutable
set stores unique values
dict stores key-value pairs
in checks membership
Study task
Write a small example or explanation for this topic. Then identify one common error related to lists, tuples,
sets, and dictionaries and describe how to fix it. This habit strengthens practical understanding and helps in
exams, labs, and interviews.
Page 7
Python Notes
7. Functions
A function is defined with def. Functions make code reusable and organized. Parameters receive input, and
return sends a result back to the caller.
Default parameter values can make functions easier to call. Keyword arguments improve clarity when a
function has several parameters.
A function should usually do one clear job. Long functions are harder to test. Good function names describe
the action, such as calculate_total or validate_email.
Key points
def defines function
return gives result
Parameters receive values
Default arguments are optional values
Study task
Write a small example or explanation for this topic. Then identify one common error related to functions and
describe how to fix it. This habit strengthens practical understanding and helps in exams, labs, and
interviews.
Page 8
Python Notes
8. Strings and Files
Strings are sequences of characters. Python provides many string methods such as lower, upper, strip,
replace, split, and join. These are useful for cleaning and processing text.
File handling commonly uses with open(...) as file. The with statement closes the file automatically. Files can
be opened for reading, writing, or appending.
When reading files, handle missing files and unexpected formats. Use try-except when there is a realistic
chance of failure.
Key points
strip removes surrounding spaces
split breaks text into parts
join combines strings
with open closes file automatically
Study task
Write a small example or explanation for this topic. Then identify one common error related to strings and
files and describe how to fix it. This habit strengthens practical understanding and helps in exams, labs, and
interviews.
Page 9
Python Notes
9. Modules and Packages
A module is a Python file containing reusable code. A package is a collection of modules. Python includes
many built-in modules such as math, random, datetime, os, and csv.
The import statement brings module features into a program. You can import a whole module or specific
functions. Use clear import style so code remains understandable.
External packages are commonly installed with pip. For data work, popular packages include pandas,
numpy, matplotlib, and scikit-learn.
Key points
import loads module
pip installs packages
math provides math functions
csv helps process CSV files
Study task
Write a small example or explanation for this topic. Then identify one common error related to modules and
packages and describe how to fix it. This habit strengthens practical understanding and helps in exams,
labs, and interviews.
Page 10
Python Notes
10. Object-Oriented Programming
Python supports object-oriented programming. A class defines a blueprint, and objects are instances of that
class. The __init__ method initializes new objects.
The self parameter refers to the current object. Instance variables store object data, and methods define
object behavior.
Inheritance allows one class to reuse features from another class. However, Python also encourages simple
designs, so functions and dictionaries may be enough for small programs.
Key points
class defines blueprint
object is instance
__init__ initializes object
self means current object
inheritance reuses behavior
Study task
Write a small example or explanation for this topic. Then identify one common error related to object-
oriented programming and describe how to fix it. This habit strengthens practical understanding and helps in
exams, labs, and interviews.
Page 11
Python Notes
11. Exceptions and Debugging
Errors are normal while programming. SyntaxError means Python could not understand the code structure.
TypeError often means an operation was used with the wrong type. IndexError means an invalid position
was used in a sequence.
The try-except structure handles runtime errors gracefully. Avoid catching every exception without
understanding it. Specific exception handling is better than hiding all errors.
Debugging habits include reading the traceback, checking the line number, printing variable values, testing
small functions, and using clear names.
Key points
try contains risky code
except handles error
Traceback shows error path
Fix one problem at a time
Study task
Write a small example or explanation for this topic. Then identify one common error related to exceptions
and debugging and describe how to fix it. This habit strengthens practical understanding and helps in
exams, labs, and interviews.
Page 12
Python Notes
12. Revision Checklist and Practice Plan
A Python learner should practice input, output, variables, conditions, loops, lists, dictionaries, functions,
strings, files, exceptions, and classes. After this foundation, data analysis and automation become much
easier.
Good beginner projects include a calculator, quiz app, contact book, expense tracker, file word counter,
student grade manager, and simple data summary program.
The best way to learn Python is to write many small programs and then improve them. First make the
program work, then make it clearer, and finally make it more reusable.
Key points
Read one small topic, type the examples yourself, and explain the output in your own words.
Keep a notebook of errors. Write the error message, the cause, and the fix.
Practice with small programs before combining many concepts together.
Use comments to explain why code is written, not to repeat every simple line.
Revise core syntax often: variables, input, conditions, loops, functions, arrays, and files.
Study task
Write a small example or explanation for this topic. Then identify one common error related to revision
checklist and practice plan and describe how to fix it. This habit strengthens practical understanding and
helps in exams, labs, and interviews.
Page 13