Intro
From the Python Programming Notes curriculum
TL;DR
Python is a popular, easy-to-read programming language you can use for many different tasks, from web development to data science. You'll write instructions in a file, and Python will run them step-by-step. Learning Python involves understanding basic concepts like variables, data types, and how to control the flow of your program.
1. The Mental Model
Think of Python as a very precise helper. You give it a list of instructions, one after another, and it follows them exactly. If you tell it to add two numbers, it adds them. If you tell it to print something, it prints it.
2. The Core Material
Python is known for its readability, which means its code looks a lot like plain English. This makes it a great language to start with!
What's a Program?

Photo by Myburgh Roux on Pexels
A program is just a sequence of instructions. When you "run" a Python program, you're telling the Python interpreter (a special program itself) to read and execute your instructions from top to bottom.
Your First Instruction: print()

Photo by Nothing Ahead on Pexels
One of the most common things you'll do is display information. The print() function does exactly that. Whatever you put inside the parentheses will be shown on your screen.
print("Hello, Python world!")
print(123)
When you run this code, it'll show:
Hello, Python world!
123
Notice how text needs to be in quotes, but numbers don't.
Variables: Storing Information

Photo by Nemuel Sereti on Pexels
Imagine you have a box, and you want to put something in it and label the box. That's what a variable does. It's a name you give to a piece of data so you can refer to it later.
greeting = "Hi there!" # 'greeting' is the variable name, "Hi there!" is the data
number_of_apples = 5 # 'number_of_apples' is the variable name, 5 is the data
print(greeting)
print(number_of_apples)
You can also change what's in the box:
x = 10
print(x) # Outputs: 10
x = 20 # Now x holds a new value
print(x) # Outputs: 20
Data Types: What Kind of Information?

Photo by Syirwan Ainu on Pexels
Variables can hold different types of data. The most common ones you'll meet first are:
- Strings (
str): Text, like"Hello"or"Python is fun". Always in quotes. - Integers (
int): Whole numbers, like1,100, or-5. - Floats (
float): Numbers with a decimal point, like3.14,0.5, or-2.7. - Booleans (
bool): RepresentsTrueorFalse. Used for logic.
Python automatically figures out the type when you assign a value.
my_text = "This is a string"
my_whole_number = 42
my_decimal_number = 3.14159
is_raining = True # Note the capital T and F
Operators: Doing Things with Data
Operators are symbols that tell Python to perform an action.
- Arithmetic Operators:
+(add),-(subtract),*(multiply),/(divide),%(remainder),**(power). - Assignment Operator:
=(assigns a value to a variable).
result = 10 + 5 # result becomes 15
print(result)
price = 15.50
quantity = 2
total_cost = price * quantity # total_cost becomes 31.0
print(total_cost)
counter = 0
counter = counter + 1 # counter becomes 1
print(counter)
Here's how Python executes a simple program:
graph TD
A["Start program"] --> B{"Read first instruction"};
B --> C{Is it a 'print' statement?};
C -- Yes --> D["Display text/value"];
C -- No --> E{Is it a variable assignment?};
E -- Yes --> F["Store value in variable"];
E -- No --> G["Execute other instruction"];
D --> H{"More instructions?"};
F --> H;
G --> H;
H -- Yes --> B;
H -- No --> I["End program"];
3. Worked Example
Let's put some of these pieces together. We'll calculate the area of a rectangle.
# 1. Define the length and width of the rectangle using variables
length = 10.5
width = 5.0
# 2. Calculate the area using the formula: area = length * width
area = length * width
# 3. Print the results in a user-friendly way
print("Length of the rectangle:", length)
print("Width of the rectangle:", width)
print("The calculated area is:", area)
# You can also combine strings and numbers in print (Python will convert numbers to text for you)
print("A rectangle with length", length, "and width", width, "has an area of", area)
When you run this code, you'll see:
Length of the rectangle: 10.5
Width of the rectangle: 5.0
The calculated area is: 52.5
A rectangle with length 10.5 and width 5.0 has an area of 52.5
4. Key Takeaways
- Python executes code from top to bottom, one instruction at a time.
- The
print()function is essential for displaying information and debugging. - Variables are names you give to store different pieces of data.
- Python automatically determines the
typeof data a variable holds (e.g., string, integer, float, boolean). - Operators like
+,-,*,/, and=perform actions on data. - Readability is a core feature of Python, making it beginner-friendly.
Common Mistakes to Avoid:
- Forgetting to put text in quotes (") when using print() or assigning a string.
- Misspelling variable names after you've created them. Python will say the name isn't defined.
- Using spaces or special characters (like - or !) in variable names; stick to letters, numbers, and underscores (_).
- Expecting a calculation to happen if you don't explicitly tell Python to perform an operation (like length * width).
5. Now Try It
Open a text editor (like VS Code, Notepad++, or even a simple text editor), type the following code into a new file, and save it as my_first_program.py. Then, open your terminal or command prompt, navigate to the folder where you saved the file, and run it using the command python my_first_program.py.
# Create a variable for your name
my_name = "Your Name Here" # Replace "Your Name Here" with your actual name
# Create a variable for your favorite number
favorite_number = 7
# Print a greeting using your name
print("Hello,", my_name + "!") # The '+' here joins two strings together
# Print a sentence about your favorite number
print("My favorite number is:", favorite_number)
# Try a simple calculation and print the result
double_number = favorite_number * 2
print("Twice my favorite number is:", double_number)
Success looks like: Seeing "Hello, Your Name Here!" and then two more sentences, one about your favorite number and another showing twice that number, all printed in your terminal.
Frequently asked about Intro
Study this next
Get the full Python Programming Notes curriculum
Clone the complete plan to your dashboard for unlimited AI-generated notes, practice quizzes, and a personalised revision schedule.
Save this course free