01 — Introduction to Programming and Python
1. Concept — What is Programming?
Programming simply means giving a computer step-by-step instructions to do a task. That's it. Nothing more magical than that.
Think about how you explain a recipe to someone who has never cooked:
| Recipe (cooking) | Program (coding) |
|---|---|
| Take 2 eggs | eggs = 2 |
| Break them into a bowl | break_eggs() |
| Whisk until fluffy | whisk() |
| If mixture is thick, add milk | if thick: add_milk() |
| Repeat whisking 20 times | for i in range(20): whisk() |
| Serve hot | print("Serve hot!") |
A computer is extremely fast but also extremely literal. It does exactly what you write — nothing more, nothing less. If you miss a step, the computer won't "guess" it. That is why we must be very careful and precise.
Why do we need programming?
Computers can do calculations and repetitive work millions of times faster than humans. But they cannot think by themselves — they need our instructions. Programming is how we convert our ideas into instructions the computer understands.
Humans and computers don't speak the same language. We speak English; the computer's brain (CPU) only understands 0s and 1s (binary). A programming language like Python is a bridge: we write code in a language that's easy for humans, and the computer converts it into 0s and 1s to run it.
2. What is Python?
Python is a programming language — a tool we use to give instructions to a computer. It was created by Guido van Rossum in 1991.
Python was designed with one big goal: be easy for humans to read and write. The creator wanted a language that felt natural — almost like writing English — instead of a language full of confusing symbols.
If you want to learn driving, you could start with a complicated race car or a simple friendly car. Python is the friendly car — easy to learn, easy to drive, yet powerful enough to go very far.
Why is Python so popular?
- Beginner friendly: Reads almost like English. Perfect first language.
- Free and open source: Anyone can use it forever, for free.
- Huge community: If you are stuck, thousands of people have solved your exact problem before.
- Used everywhere: Web apps, data science, artificial intelligence, games, automation, scientific research, and more.
- Works on all platforms: Windows, macOS, Linux — same code everywhere.
Features of Python
Interpreted
Your code runs line by line, immediately. No separate compile step needed — great for beginners.
Dynamically typed
You don't have to declare variable types. Python figures them out for you.
Object-oriented + Functional
Supports multiple styles of writing code — you'll meet these later.
Batteries included
Thousands of ready-made tools (modules) come built in, so you rarely start from scratch.
3. Interpreter and Script
When you write Python, you can use it in two different ways:
Way 1 — Interactive Mode (the Interpreter)
You type one line, press Enter, and Python answers you immediately. It's like talking to someone in a chat.
>>> print("Hello")
Hello
>>> 2 + 3
5
The >>> symbol is called the prompt. It is Python saying: "I'm ready, type something."
Way 2 — Script Mode (the Script)
A script is simply a file containing Python code (file name usually ends with .py, like hello.py). You write all your instructions in the file, then run the whole file at once. This is how real programs are built.
| Interactive Mode | Script Mode |
|---|---|
| One line at a time | Whole file at once |
| Good for quick experiments | Good for real programs |
| Nothing is saved | Code is saved in a file |
- Source code: You write Python code (human-friendly).
- Compiler: Python secretly converts your code into bytecode — a low-level intermediate form the computer can process faster.
- Interpreter (Python Virtual Machine): Reads the bytecode line by line and executes it on your machine.
- Result: You see the output.
You don't need to remember these details now. Just know the big picture: your code is converted into something the computer can run, then it runs line by line.
4. Your First Python Program
Every programming journey starts with a tradition: make the computer greet the world. Create a file called hello.py and type:
print("Hello, World!")
Let's explain this line piece by piece:
print— a function (a pre-made command) that shows text on the screen.()— the parentheses hold the input we give to the function, called its argument."Hello, World!"— a string (a piece of text). The quotes tell Python: "this is text, not code."
Python is a very "English-like" language. Try reading print("Hello") aloud: "Print Hello." That is exactly what it does.
5. Examples — Level by Level
print("Welcome to Python!")
This prints one line of text. Everything inside the quotes is text; nothing more happens.
We can print multiple lines using multiple print() calls:
print("Line one")
print("Line two")
print("Line three")
>>> Line two
>>> Line three
Each print() automatically moves to the next line after printing. That's why the three messages appear one below the other.
Python can do calculations too. Type 2 + 3 — Python computes the answer and print shows it:
print(2 + 3)
Notice: no quotes around 2 + 3. Quotes would make it text ("2 + 3"), but without quotes Python treats it as math and actually calculates it. This small difference is the start of your programming instinct!
Can you guess the output of this?
print("2 + 3")
Reveal output
Because of the quotes, Python prints the text "2 + 3". It does not calculate. Quotes = text, no quotes = code. Remember this!
6. Dry Run — See it happening
Let's watch a small program run step by step. This habit — called a dry run — is how programmers mentally check their code.
print("Start")
print(5 * 2)
print("End")
| Step | Code being executed | What it does | Screen |
|---|---|---|---|
| 1 | print("Start") | Prints the text "Start" | Start |
| 2 | print(5 * 2) | First multiplies 5×2 = 10, then prints it | 10 |
| 3 | print("End") | Prints the text "End" | End |
Python reads and runs your code from top to bottom, one line at a time. The order matters. If you swap the lines, the output order changes too. This "top to bottom" idea is the foundation of every program you'll ever write.
7. ⚠️ Common Beginner Traps
print(Hello) → Error! Python thinks Hello is a variable name, not text. Always wrap text in quotes: print("Hello").
print('Hello") → Error! The opening quote (') and closing quote (") don't match. Python allows either, but they must match each other.
print("Hello" → Error! Every opening ( needs a matching closing ). Count them whenever you get a strange error.
Print("Hello") with a capital P → Error! Python is case-sensitive. print, Print, and PRINT are three completely different things to Python.
Beginners are used to English where small mistakes are forgiven. Python is not forgiving — it needs exact spelling. Think of Python like a strict teacher who needs perfect handwriting. The good news: errors tell you exactly what's wrong. Read them!
8. 🧠 Think Before You Code
Before solving any problem, ask yourself these questions. This habit will save you hours of confusion.
- What is the input? — What information do I have?
- What should the output be? — What do I want to see?
- Which concept is required? — Printing? Math? Loops?
- Can I break it into smaller steps? — Solve one small piece at a time.
Example: "Print your name and your age on two separate lines."
- Input: nothing — I already know my name and age.
- Output: my name, then my age, each on its own line.
- Concept:
print()— I'll need twoprint()calls, or one print with a\n. - Smaller steps: print name first, then print age.
print("Ravi")
print(20)
9. 🎯 Practice Questions
Try each question yourself first. Use the Hint button only if stuck, and the Solution button only after you've genuinely tried. Then read the Explanation to truly understand why.
What is programming? Explain in one simple sentence.
What will this print?
print("Hello")
print(10 + 5)Hello
15
10 + 5 as mathematics, calculates 15, and prints the result. Quotes mean text; no quotes means code/math.What is wrong with this code?
print(Hello World)print("Hello World")Hello World has no quotes, so Python sees two "words" it doesn't recognize and gets confused. Always wrap text in quotes: print("Hello World").The file extension for a Python script file is ______.
.py (for example: hello.py).py extension so that Python (and humans) know it's a Python file.The code below gives an error. Fix it.
print("I am learning Python")") — the quote and parenthesis are swapped. Correct: print("I am learning Python")" opens the string, the text follows, then " closes the string, and finally ) closes the function call. If the order is wrong, Python raises a syntax error.Write a Python program that prints your name, your favorite food, and the result of 25 divided by 5 — each on its own line.
print() calls. Remember: text needs quotes, math doesn't.print("Ravi")
print("Pizza")
print(25 / 5)
print() statements run top to bottom. Names and foods are text → quotes. 25 / 5 is math → no quotes → Python calculates 5.0 and prints it.Print a simple face using text on one line using only ONE print(). (Hint: it may help to know \n makes a new line inside a string.)
\n between the rows of your face inside one set of quotes.print(" -----\n| o o |\n| ^ |\n -----")
\n is a special character called a newline — it moves to the next line. Even though it's one print(), the output has 4 lines. This is a sneak peek at strings, which we study deeply in Topic 13.