LearnPy Hub
BasicsBeginnerLesson 1 of 32

Introduction & print()

Watch the ideaFrom your code to the screen
print("Hello, World!")
your code
Python
screen

You write an instruction. print() means “show this on the screen”.

1Level 1 · BasicsBasics

Welcome! This first lesson assumes you have never written code before. By the end you'll have run your first Python programs right here in the browser. You don't need to install anything.

What is programming?

A program is a list of instructions for a computer. The computer follows them exactly, one line at a time, from top to bottom. A programming language is the way we write those instructions. Python is one of the most popular languages in the world because its code reads almost like English.

People use Python for websites, automating boring tasks, games, data analysis, science and machine learning. Everything you learn here, from print() to pandas, is the same Python the professionals use.

Your first instruction: print()

print() shows something on the screen. Whatever you put inside the round brackets is printed:

print("Hello, world!")
  • Text goes inside quotes. Double quotes "hi" and single quotes 'hi' both work. A piece of text is called a string.
  • Numbers don't need quotes: print(42). You can even do maths: print(2 + 3) prints 5.
  • Each print() starts on a new line.

Printing several things at once

Separate items with commas. Python puts a space between them:

print("I am", 20, "years old")   # I am 20 years old

Two optional settings change this. sep sets what goes between the items, and end sets what goes at the end (normally a new line).

How to use the examples

Every lesson has editors with a ▶ Run button. Press it to run the code. Then change something and run it again. Breaking things on purpose is a great way to learn. Reset brings the original code back.

Key points: a program runs from top to bottom; print() shows output; text needs quotes, numbers don't; commas print several items with spaces between them.

See it in actionPython runs one line at a time

Press Play and watch the arrow move down the program. Each print() adds a line to the output.

Step-by-step

Try it yourselfExample 1: Hello, world

Press Run. Then change the message to your own name and run it again.

example_1.py
Output appears here
Fill in the blanks

Say hello

Fill the blank so the program prints Hello, Python!.

blanks.py
print()

Example 2: Maths inside print()

Python works out the sum first, then prints the answer. Text in quotes is printed exactly as written, even if it looks like maths.

example_2.py
Output appears here
Fix the bug

A missing quote

This should print I love coding, but Python stops with an error. Press Check to see it, then fix the line.

buggy.py

Example 3: sep and end

sep goes between items; end goes after the last one. Try sep=", " or end="!!!\n".

example_3.py
Output appears here
Fill in the blanks

Join with dashes

Fill the blanks so the output is 2026-11-06 (no spaces).

blanks.py
print(2026, 11, "06", ="")
Your turn

Two lines, one print

Using one print() call, print Name: Mim on the first line and Class: 7 on the second.

my_code.py

Example 4: A tiny receipt

Several print() lines together make a small, readable output.

example_4.py
Output appears here
Your turn

Let Python do the maths

A notebook costs 45 taka and a pen costs 15 taka. Print Total: 60, letting Python add the two prices.

my_code.py

2Level 2 · IntermediatePrinting like a pro

You can already print text and numbers. Now let's control exactly how the output looks.

Escape characters

Inside a string, a backslash starts a special character: \n is a new line, \t is a tab, \" is a quote mark and \\ is a backslash itself.

print("Name:\tRahim\nAge:\t15")

Multi-line strings

Three quote marks let a string run over several lines, exactly as you type it. Handy for menus, poems and ASCII art.

Repeating text

"-" * 20 makes a line of 20 dashes. Multiplying a string by a whole number repeats it.

See it in actionWatch print() build the output

Step through and watch each print add to the output, including the line breaks from \n.

Step-by-step

Example 5: Escape characters and repeated lines

Change the tab \t to a few spaces and compare the alignment.

example_5.py
Output appears here

Example 6: A multi-line menu

Triple quotes keep every line break you type.

example_6.py
Output appears here

3Level 3 · AdvancedHow Python runs your program

Before going further, it helps to know what happens when you press Run.

Interpreted, line by line

Python reads your file from top to bottom. It first checks the whole file for syntax errors (like a missing bracket). If there are none, it runs the lines in order. An error in line 5 means lines 1 to 4 already ran.

print() is a function with options

print(*values, sep=" ", end="\n"): it takes any number of values, joins them with sep and finishes with end.

Syntax errors stop everything

A syntax error (like a missing bracket or quote) is found before anything runs, so not even the first line prints. A runtime error (like dividing by zero) happens while running, so the lines before it have already printed.

Remember: Python stops at the first error it meets while running, so read error messages from the bottom line up.

See it in actionPython stops at the first error

Watch lines 1 and 2 run, then line 3 raise an error. Line 4 never runs.

Step-by-step

Example 7: A neat receipt with aligned columns

Python works out each total for you. Add a line for an eraser that costs 5 Tk and fix the grand total.

example_7.py
Output appears here

Example 8: Lines run in order until an error

The SyntaxError is a mistake in the code itself, so nothing runs at all, not even line 1. Fix the missing bracket and run again.

example_8.py
Output appears here
Common mistakePython is case-sensitive. Print("hi") gives a NameError because the function is called print in lowercase. Also check your quotes match: print("hi') is a SyntaxError.
Exercise · predict the output

What does this program print?

print("Py", "thon", sep="")
Quick quiz · 4 questions
1. Which line prints the word Hello?
2. What is the default separator between items in print()?
3. What does print("2 + 2") show?
4. In which order does Python run the lines of a program?
Ready to practice introduction & print()?

50 graded problems are waiting in Topic Practice.

Practice this topic →
Python Introduction & print() · LearnPy Hub