What is a program? What is Python?
A program is a list of instructions a computer follows, one after another. Python is a programming language: a way of writing those instructions that is close to plain English.
Python is used by beginners and by large companies alike. It runs websites (Instagram, parts of YouTube), analyses data, trains AI models and automates boring office work. It is popular in schools because the code is short and easy to read.
print("Namaste, Python!")
That one line is a complete Python program. In many other languages the same job needs five or more lines.
Installing Python and an editor
- Download Python 3 from python.org and run the installer.
- On Windows, tick Add python.exe to PATH on the first screen before you click Install.
- Install VS Code as your editor, and add its Python extension.
Check the install by opening Command Prompt and typing python --version. You should see something like Python 3.12.4.
There are two ways to run Python:
| Way | What it is | Use it for |
|---|---|---|
Shell (IDLE or python in a terminal) | Type one line, see the answer at once | Quick tests, a calculator |
Script (a .py file) | Write many lines, save, then run | Real programs you want to keep |
print(): show something on the screen
print() displays whatever you put inside the brackets.
print("Hello") # text must be in quotes
print(25) # numbers need no quotes
print(10 + 5) # Python works out the sum first: 15
print("Age:", 16) # many items, separated by commas
Text in quotes is called a string. You can use single quotes 'Hi' or double quotes "Hi"; both work the same.
sep and end
When you print several items, Python puts a space between them and a new line at the end. You can change both.
print("10", "05", "2026", sep="-") # 10-05-2026
print("Loading", end="...")
print("done") # Loading...done
sepsets what goes between items (default: a space).endsets what goes after the last item (default: a new line,\n).
Escape characters
| Code | Meaning |
|---|---|
\n | new line |
\t | tab (lines text up in columns) |
\" | a double quote inside a double-quoted string |
print("Name:\tAsha\nClass:\t10")
Comments
A comment starts with #. Python ignores everything after it on that line. Use comments to explain *why* the code does something.
# Calculate the total fee for one student
fee = 1200 # monthly fee in rupees
How Python runs your program
Python reads your file from top to bottom, one line at a time. If line 5 has an error, lines 1 to 4 have already run, and line 6 never runs.
Reading error messages
When something is wrong, Python stops and prints an error. The last line tells you the *type* of error, and the line number tells you *where*.
File "hello.py", line 2
print("Hi"
^
SyntaxError: '(' was never closed
Three errors every beginner meets
| Error | Cause | Example |
|---|---|---|
SyntaxError | Python cannot understand the line: a missing bracket or quote | print("Hi" |
NameError | You used a name Python does not know, often a spelling mistake | prnt("Hi") |
IndentationError | Spaces at the start of a line where none are expected (or missing) | print("Hi") |
Tip: read the error from the bottom up. The last line says what went wrong; the line number above it says where.
Common mistakes
- Forgetting quotes around text:
print(Hello)gives aNameError, because Python thinksHellois a variable. - Writing
Printwith a capital P. Python is case-sensitive:printandPrintare different names. - Using curly “smart quotes” copied from Word or WhatsApp. Python only accepts plain
"and'.
Key points
- A Python program is a text file ending in
.py, run from top to bottom. print()shows text and values;sepandendchange spacing and line endings.#starts a comment that Python ignores.- Read errors from the bottom line up, and check the line number.
Practice questions
1. What does print("A", "B", "C", sep="") show?
ABC. An empty sep means nothing goes between the items.
2. Write one print statement that shows your name and class on two separate lines.
print("Name: Riya\nClass: 9")3. A student types print("Total" 50). Which error appears, and how do you fix it?
A SyntaxError, because the two items need a comma between them: print("Total", 50).
4. What is the output of these two lines?
print("Good", end=" ")
print("morning")
Good morning on one line, because end=" " replaced the usual new line with a space.
5. Why does prnt("Hello") give a NameError and not a SyntaxError?
The line is grammatically fine, but Python does not know any function called prnt. Unknown names cause a NameError.