The Bill from the Corner Shop
When Lakshmi buys groceries at Sri Balaji Stores in Madurai, the shopkeeper hands her a small printed bill. The shop name is at the top, each item sits on its own line, the prices stand in a neat column, and the total is at the bottom. A clear bill helps everyone: the customer can check it, and the shopkeeper looks professional.
A computer program also needs a way to show its results to people. In Python, the instruction that does this is print(). It is the first tool every Python programmer learns, and you will use it in almost every program you ever write.
In this lesson you will learn to print text and numbers, control spaces and lines, add special characters like tabs, and write comments: notes for humans that Python ignores. At the end you will print a complete shop bill.
print(): Showing Text and Numbers
print() is a function: a named, ready-made action. You write its name, then round brackets, and inside the brackets the value you want to show. Run this example:
print("Welcome to Sri Balaji Stores") # Welcome to Sri Balaji Stores
print(250) # 250
print(99.5) # 99.5
print(120 + 45) # 165
print("120 + 45") # 120 + 45
Look closely at the last two lines:
print(120 + 45)has no quotes. Python calculates the sum and prints165.print("120 + 45")has quotes, so it is text. Python prints it exactly as written.
Text inside quotes is called a string. You can use double quotes "Hello" or single quotes 'Hello'. Both work the same, but the start and end quote must match.
Every example on this page runs in your browser. Press ▶ Try it yourself, change something, and press Run again. Breaking things on purpose is a great way to learn.
Printing Several Values with Commas
You can give print() more than one value. Separate them with commas. Python prints them on one line and puts one space between each value. This is very useful for a label followed by a number.
print("Item:", "Sugar") # Item: Sugar
print("Price:", 45, "rupees") # Price: 45 rupees
print("Total for 2 kg:", 45 * 2) # Total for 2 kg: 90
You did not type a space after "Price:", but the output has one. The comma adds it for you.
sep and end: Controlling Spaces and Lines
print() has two optional settings that you write inside the brackets after your values:
| Setting | What it controls | Normal value |
|---|---|---|
sep | What goes between the values | One space |
end | What goes at the end of the line | A new line |
# sep: what goes BETWEEN the values (normally a space)
print("12", "08", "2026", sep="-") # 12-08-2026
print("Rice", "Dal", "Oil", sep=", ") # Rice, Dal, Oil
print("Rs.", 450, sep="") # Rs.450
# end: what goes at the END of the line (normally a new line)
print("Printing your bill", end="...")
print("done") # Printing your bill...done
Because end="..." replaced the new line, the next print() continued on the same line. sep="" (two quotes with nothing inside) means “put nothing between the values”, which is handy for Rs.450.
Blank Lines
A print() with nothing inside the brackets prints an empty line. Use it to make your output easier to read, like the gap between the shop name and the items on a bill.
print("Sri Balaji Stores")
print()
print("Thank you for shopping with us.")
Escape Characters: Special Symbols Inside Text
Some characters are hard to type inside a string. How do you put a new line in the middle of a text, or a double quote inside double quotes? Python uses a backslash \ followed by a letter. These pairs are called escape characters.
| Write this | You get |
|---|---|
\n | A new line |
\t | A tab (a jump to the next column) |
\" | A double quote inside a string |
\' | A single quote inside a string |
\\ | One backslash |
print("Line one\nLine two") # \n starts a new line
print("Rice\t325") # \t adds a tab space
print("She said \"Visit again\"") # \" puts a double quote inside
print('It\'s a fresh stock day') # \' puts a single quote inside
print('The shop is called "Sri Balaji"') # or use the other kind of quotes
print("Folder: C:\\bills") # \\ prints one backslash
Notice the fifth line: if your text has double quotes inside, you can simply wrap it in single quotes, and the other way round. Many programmers find that easier than escape characters.
Comments: Notes for Humans
A comment starts with a # sign. Python ignores everything from the # to the end of that line. A comment can sit on its own line or after some code.
# This program prints the shop's opening hours.
# Written by Lakshmi, for the notice board.
print("Open: 8 AM to 9 PM") # weekdays
print("Sunday: 9 AM to 1 PM")
# print("Closed on Diwali") <- this line is switched off
Only two lines are printed. The last print() is “commented out”: putting # in front of it switches it off without deleting it. In VS Code, select some lines and press Ctrl + / (Cmd + / on a Mac) to add or remove the # on all of them at once.
Why comments matter
- They explain why. Code shows what happens. A comment can say why you did it that way.
- They help future you. In three months you will forget what you were thinking. A short note saves time.
- They help your team. Other people can understand and change your program safely.
Good comments are short and useful. You do not need a comment on every line, only where something is not obvious.
Real-Life Example: Printing a Shop Bill
Here is Lakshmi’s bill from Sri Balaji Stores, printed by Python. It uses everything from this lesson: plain text, tabs for columns, a calculation, sep, end and comments.
# Sri Balaji Stores: a printed bill
# \t moves the text to the next column
print("--------------------------------")
print(" SRI BALAJI STORES")
print(" Main Road, Madurai")
print("--------------------------------")
print("Item\t\tQty\tAmount")
print("Rice 5 kg\t1\t325")
print("Toor dal 1 kg\t1\t160")
print("Sugar 1 kg\t2\t90")
print("Milk 500 ml\t4\t108")
print("--------------------------------")
print("Total\t\t\t", 325 + 160 + 90 + 108, sep="") # sep="" removes the extra space
print("Paid by UPI", end=". ")
print("Thank you! Visit again.")
The output looks like this:
--------------------------------
SRI BALAJI STORES
Main Road, Madurai
--------------------------------
Item Qty Amount
Rice 5 kg 1 325
Toor dal 1 kg 1 160
Sugar 1 kg 2 90
Milk 500 ml 4 108
--------------------------------
Total 683
Paid by UPI. Thank you! Visit again.
Each \t moves the text to the next column, so the quantities and amounts line up. Short item names need two tabs to reach the same column as long ones. The exact width of a tab can differ a little between screens.
Try these changes:
- Add a new item,
Oil 1 L, quantity 1, price 150. Remember to add 150 to the total too. - Print a blank line between the shop address and the dashes.
- Change
end=". "toend="\n"and see what happens to the last two lines.
Common Mistakes
- A missing quote. If a string starts with a quote but never ends with one, Python cannot tell where the text stops. The program does not run at all:
print("Thank you for shopping) # ERROR: SyntaxError
Python shows a SyntaxError that says the string was not closed (the exact words depend on your Python version). The fix is to close the string with the same kind of quote:
print("Thank you for shopping") # Thank you for shopping
- Mixing quote types.
print("Hello')starts with a double quote and ends with a single one. Both ends must match. - Using a slash instead of a backslash.
/nis just two ordinary characters. A new line needs the backslash:\n. - Forgetting the brackets.
print "Hello"was allowed in the very old Python 2. In Python 3,printalways needs brackets:print("Hello"). - Expecting a comment to print. Text after
#never appears in the output. If you want people to see it, put it insideprint().
Practice Task: A Chai Stall Bill
Anna runs a small tea corner near a college. Help him print a bill. Complete the TODO steps in the starter code. Your program should:
- Print the name Anna's Tea Corner (watch out for the single quote)
- Print a line of dashes above and below the items
- Print three items with a
\tbetween each name and its price - Print the total, calculated by Python
- Print the date
15/08/2026usingsep="/" - Have at least one comment
# Chai stall bill
# TODO 1: Print the stall name "Anna's Tea Corner" (it has a single quote inside!)
# TODO 2: Print a line of dashes
# TODO 3: Print three items with \t between the name and the price:
# Masala chai 20, Bun butter 30, Samosa 15
# TODO 4: Print the total, letting Python add the three prices
# TODO 5: Print today's date as 15/08/2026 using sep="/"
Show one possible answer (try it yourself first!)
# Chai stall bill
print("Anna's Tea Corner")
print("------------------------")
print("Masala chai\t20")
print("Bun butter\t30")
print("Samosa\t\t15")
print("------------------------")
print("Total\t\t", 20 + 30 + 15, sep="") # Total 65
print("15", "08", "2026", sep="/") # 15/08/2026
Key Takeaways
print()shows text (in quotes) and numbers (without quotes). Calculations without quotes are worked out first.- Commas print several values with one space between them.
sepchanges the gap, andendchanges what comes at the end of the line. - An empty
print()prints a blank line. - Escape characters start with a backslash:
\nfor a new line,\tfor a tab,\"and\'for quotes. - Comments start with
#. Python ignores them, but people reading your code will thank you.