Variables and data types
How does a shopping app remember your cart and work out your bill? See how programs follow steps, store values in variables and handle numbers, text and true or false.

Instructions for a new helper
Asha runs a stationery shop in Indore. Her new helper knows nothing, so she writes exact steps: take the price, multiply by the quantity, tell the customer.
A computer is the same kind of helper. A list of exact steps for it is called a “program”.
Your first program
Computers don’t follow English. We write the steps in a programming language, and ours is Python.
print("Asha Stores")print("Indore")Asha StoresIndoreprint shows whatever is inside the brackets. Python runs the lines from top to bottom.
Python as a calculator
Kabir buys 3 notebooks at ₹40 each, adds a ₹30 pen and pays with a ₹200 note.
print(3 * 40)print(120 + 30)print(200 - 150)12015050* multiplies and / divides. Search for “online Python editor” and try your own sums.

Labelled boxes
Asha keeps a box labelled “Notebook price” with a slip inside that says 40. When the price changes, she swaps the slip. The label stays.
Programs need the same thing: a place to keep a value, with a name to find it again.
Variables
A named box in a program is called a “variable”. The = sign puts a value in the box.
price = 40qty = 3total = price * qtyprint(total)120Python opens the price and qty boxes, multiplies the values and stores the result in a new box, total.
Changing a value
Kabir now wants 5 notebooks. We put a new value in the same box:
qty = 3qty = 5print(qty)print(40 * qty)5200A box holds only its latest value, so the old 3 is gone. The value can vary, hence the name variable.

Different kinds of values
Look at one of Asha’s bills. It has a customer name, a quantity, a GST rate and a “Paid” stamp.
You can multiply a quantity, but you can’t multiply a name. Python also sorts values into kinds, called “data types”.
Numbers: int and float
Python has 2 types of numbers. Whole numbers are “int”, short for integer. Numbers with a decimal point are “float”.
total = 200gst = total * 0.18print(gst)36.0Here 200 is an int and 0.18 is a float. Say GST is 18%. On ₹200, it comes to ₹36.
Strings
Text is a third type. We write it inside quotes, and Python calls it a “string”, or “str” for short.
name = "Kabir"shop = "Asha Stores"print(name)print(len(shop))Kabir11len counts the characters in a string, spaces included.
True or false
Has Kabir paid? The answer is only yes or no. Python has a type for this, called “bool”, with just 2 values: True and False.
paid = Trueprint(paid)print(type(paid))True<class 'bool'>type tells us the data type of any value.
Mixing types
What if the quantity arrives as text, like "3" typed into a form?
qty = "3"print(qty + 2)TypeError: can onlyconcatenate str (not "int")to strPython stops with an error, because text and a number can’t be added. Always read the error’s last line first. The fix: int(qty) + 2 gives 5.
The full bill
Let’s put it all together for Kabir’s bill:
name = "Kabir"total = 5 * 40gst = total * 0.18bill = total + gstprint(f"{name} pays ₹{bill}")Kabir pays ₹236.0The f before the quotes lets us drop variables into a string using curly brackets.
Summary
- Program: A list of exact steps that a computer runs from top to bottom.
- Variable: A named box that stores a value. The
=sign puts a value in it. - Data types: int and float for numbers, str for text and bool for True or False.
- Errors: Types don’t mix freely. Read the error’s last line, then convert with
int().