Python Lesson 1: Install Python & Run Your First Code (REPL + .py Files)
Start coding today! In this beginner-friendly lesson you'll install Python, verify it works, and write your very first print statement. What you'll learn: β’ What Python is and the key terms every beginner needs β’ Installing Python step by step and checking it worked β’ Using the REPL to "chat" with Python β and how to exit it β’ Writing and running your first .py script file β’ REPL vs script files, common beginner mistakes, and other ways people run Python By the end, you'll be fully set up and ready for Lesson 2! #Python #LearnPython #PythonForBeginners #Coding #Programming
8. Introduction
Every software career starts with a single, slightly nervous moment: you install a programming language, type a command, and wait to see if the machine talks back. This lesson is about that moment for Python.
You might wonder why a setup lesson deserves this much attention. After all, no interviewer will ever ask you to "install Python" on a whiteboard. But here's the truth that separates people who finish learning to code from people who quietly quit in week one: a broken environment kills more beginners than hard algorithms ever will. If python doesn't run, you can't practice. If you can't practice, you can't learn Data Structures, Algorithms, or anything you'll actually be tested on in a Coding Interview.
So this lesson is really about removing friction. By the end, you'll understand what Python is, how to install it correctly, the two fundamental ways to run code (the REPL and script files), and why professional engineers use both. Master this, and every future lesson becomes easy. Skip it, and you'll fight your tools forever.
9. Problem Overview
Let's frame this like a real problem to solve, because it is one.
The goal: get a working Python environment on your computer and prove that you can run code two different ways.
Python is a programming language β a structured way to write instructions that a computer follows precisely. It's popular in Software Engineering because it reads almost like plain English, which lowers the barrier for beginners while still powering serious production systems.
To run Python code, you need three things working together:
- The interpreter β the program that reads your Python instructions and executes them.
- A way to talk to it β either interactively (the REPL) or through a saved file (a script).
- The terminal β the plain text window where you type commands to your computer.
The "problem" we're solving: install the interpreter, confirm it works, and successfully execute your first instruction using both interactive and file-based methods.
10. Example
Let's define what success looks like with concrete inputs and outputs.
Interactive example (REPL):
Input: 2 + 3
Output: 5
Input: print("hello world")
Output: hello world
When you type 2 + 3 and press Enter, Python evaluates the expression immediately and shows 5. There's no "run" button β the moment you hit Enter, it computes. That's the defining trait of the REPL.
Script example (hello.py):
print("hello world")
print("I am learning Python")
Running this file produces:
hello world
I am learning Python
Same print output, but stored in a file you can run again tomorrow, next week, or send to a friend. That permanence is the entire difference between the two approaches.
11. Intuition
Here's how an experienced engineer thinks about this, stripped of jargon.
Imagine you just moved into a new kitchen. Before you cook anything, you need the stove installed and working. Installing Python is installing the stove. You don't celebrate the stove β you celebrate the first meal β but without it, nothing else happens.
Now, once the stove works, you have two styles of cooking:
- Tasting as you go β you throw one ingredient in, taste it instantly, adjust. That's the REPL: type one line, see the result immediately, experiment freely. Perfect for "what does this do?" But when you close the kitchen, nothing is written down.
- Following a written recipe β you write every step in order, save the recipe, and can cook the exact same dish a hundred times. That's a script: a
.pyfile Python reads top to bottom.
The intuition that separates beginners from professionals is this: you don't choose one. You taste-test in the REPL while figuring something out, then move the finished logic into a script so it lasts. The REPL is for discovery; the file is for building.
Once you internalize that, the mechanics β installers, PATH, quotes β are just details.
12. Brute Force Solution
The "brute force" way beginners often start is the online playground approach: skip installation entirely, go to a website like Replit, and type code in the browser.
Idea: Avoid the setup friction. Use someone else's pre-installed Python.
Algorithm:
- Open a browser.
- Go to an online Python playground.
- Type code, click run.
Advantages:
- Zero installation.
- Works on locked-down machines (school, work).
- Great for a first five-minute taste.
Disadvantages:
- Requires internet every single time.
- Often slow to start.
- Doesn't teach you the terminal, PATH, or file management β skills you'll need forever.
- You never actually learn to run Python on your own machine.
Time complexity: Setup is O(1) β instant. But your learning is bounded, because you never build the real muscle.
Space complexity: O(0) on your disk β nothing is installed, which is exactly why it's a dead end for serious learning.
This works to try Python, but it doesn't work to learn it. So we go one level deeper.
13. Optimal Solution
The optimal approach is a proper local install. Here's every step.
Step 1 β Download and install
Go to the official website, python.org, click download, and run the installer.
β οΈ Windows users β the one critical step: The installer shows a checkbox labeled "Add Python to PATH." Tick it. PATH is the list of folders your computer searches when you type a command. Ticking the box lets you type
pythonfrom any folder. Skip it, and your computer won't know where Python lives.
Step 2 β Verify the install
Open your terminal and run:
python --version
| Result | Meaning |
|---|---|
Python 3.12.x (or similar) |
β Success β you're ready. |
python is not recognized |
β PATH wasn't set. Rerun the installer and tick the box. |
Step 3 β Meet the REPL
Type python alone and press Enter. You'll see >>> β Python saying "I'm listening."
>>> 2 + 3
5
>>> print("hello world")
hello world
REPL stands for ReadβEvaluateβPrintβLoop, but think of it as a live conversation. To leave, type:
exit()
(On Mac/Linux, Ctrl+D also works; on Windows, Ctrl+Z then Enter.)
Step 4 β Write a script
Create a file named hello.py in any text editor, add your code, and save it. The .py extension marks it as a Python file. Then run it from the terminal:
python hello.py
The word python hands your file to the interpreter, which reads it top to bottom and prints your messages.
14. Python Code
# hello.py
# Your first Python script.
# print() displays a message on the screen.
# The text inside quotes is a "string" β Python shows it exactly as written.
print("hello world")
print("I am learning Python")
# You can also do math and print the result.
print(2 + 3) # -> 5
15. Code Walkthrough
Let's read this line by line.
print("hello world")βprintis a built-in function that sends text to the screen. The parentheses()hold what you want to print. The double quotes"..."are fences that tell Python where your text begins and ends.print("I am learning Python")β Python runs files top to bottom, so this line executes right after the first. Order matters.print(2 + 3)β Notice there are no quotes around2 + 3. Because it isn't quoted, Python treats it as math, evaluates it to5, and prints the number. Quotes would have printed the literal characters2 + 3instead.
That contrast β quoted text versus unquoted expression β is one of the most important early lessons in Python.
16. Dry Run
Let's trace python hello.py step by step.
| Step | What Python does | Screen output |
|---|---|---|
| 1 | Opens hello.py, starts at line 1 |
β |
| 2 | Skips comment lines (#) |
β |
| 3 | Executes print("hello world") |
hello world |
| 4 | Executes print("I am learning Python") |
I am learning Python |
| 5 | Evaluates 2 + 3 β 5, prints it |
5 |
| 6 | Reaches end of file, stops | β |
Final output:
hello world
I am learning Python
5
Python read the recipe top to bottom, ignored the comments, and executed each instruction in order. No surprises β and that predictability is exactly what makes it beginner-friendly.
17. Complexity Analysis
Time complexity: Running a script with n lines of straight-line code is O(n) β Python reads and executes each instruction once, in order. Our three print calls are O(3), which is constant work.
Space complexity: O(1) β we store no growing data structures; each print uses a fixed, small amount of memory and releases it.
Why is this correct? Because there are no loops, no recursion, and no data that grows with input. Each line does a bounded amount of work exactly once. As you move into future lessons with Data Structures and Algorithms, these same Big-O ideas will scale up β this is your first, gentle exposure to them.
18. Alternative Solutions
Beyond the terminal-plus-editor workflow, you have several editors to run Python. Here's an honest comparison:
| Tool | Setup effort | Best for | Trade-off |
|---|---|---|---|
| IDLE (bundled with Python) | None | Absolute beginners | Plain, minimal features |
| VS Code | A few minutes | Real projects, long-term | Setup required, but industry standard |
| Online playground (Replit) | None | Quick tries, no install | Needs internet, can be slow |
| Terminal + editor | Low | Learning fundamentals | You manage files yourself |
For learning, any of these is fine. But VS Code is where most professional Software Engineering work happens, so it's a smart tool to grow into.
19. Edge Cases
- Empty file: Running
python empty.pyproduces no output and no error. Python read zero instructions, so it did zero work. This is valid. - Wrong folder: If the terminal says it can't find
hello.py, you're in the wrong directory. Usecdto move to the folder where you saved the file. - Old Python 2: On some systems,
pythonpoints to an outdated version. Trypython3 --versionifpythonbehaves oddly. - File saved with wrong extension: Saving
hello.py.txtmeans Python won't recognize it. Confirm the real extension is.py.
20. Common Mistakes
- Forgetting to tick "Add Python to PATH." The number one Windows install failure. If
pythonisn't recognized, this is almost always why. - Forgetting the quotes.
print(hello)makes Python thinkhellois a variable it has never heard of β you'll get aNameError. Useprint("hello"). - Capitalizing
print. Python is case-sensitive.Print(...)is a stranger to it and raises an error. It must be lowercaseprint. - Running the file from the wrong folder. "File not found" almost always means you need to
cdinto the correct directory first. - Typing
exitwithout parentheses to leave the REPL. The correct call isexit()β the parentheses matter because it's a function call.
21. Interview Questions
Even a setup lesson has follow-ups a mentor or interviewer might ask:
- What is the difference between an interpreter and a compiler?
- What does the REPL acronym stand for, and when would you prefer it over a script?
- What is the PATH environment variable, and why does it matter?
- Why does
print("2 + 3")output2 + 3whileprint(2 + 3)outputs5? - How would you run a Python file from the command line, and what does the
pythoncommand actually do?
22. Similar Problems
These beginner LeetCode and practice concepts build directly on today's foundation:
- "Fizz Buzz" (LeetCode 412) β your first taste of printing output based on logic; relies entirely on running scripts.
- "Hello World" style challenges β the natural next step after your first
print. - Variable and type problems β the very next lesson, where Python gains a memory.
They're related because every one of them assumes you can already run Python. Today removed that blocker.
23. Key Takeaways
- Python is a language for giving computers precise instructions, prized for reading like English.
- Install from python.org, and on Windows tick "Add Python to PATH."
- Verify with
python --version. - The REPL runs one line instantly β ideal for experiments. Exit with
exit(). - A script (
.pyfile) saves your code so it's permanent, repeatable, and shareable. - Real developers use both: experiment in the REPL, build in files.
- Errors are just Python asking you to check your spelling, capitalization, and quotes.
24. Watch the Video
Reading the steps is one thing β seeing the terminal respond in real time makes it click. Watch the full walkthrough here, where every command is demonstrated live from install to your first print:
βΆοΈ {LINK}
25. About the Series
This is Lesson 1 of the Daily Python LeetCode series β a step-by-step path that takes you from installing Python to confidently solving Coding Interview problems. Each lesson is short, practical, and builds on the last: today you set up your environment; next, we give Python a memory with variables; soon after, we tackle real Algorithms and Data Structures. Follow along daily and you'll have a genuine Software Engineering foundation before you know it.
26. Call To Action
If this helped you get set up:
- π Subscribe on YouTube so you never miss a lesson.
- π¬ Subscribe on Substack to get each write-up delivered straight to your inbox.
- π¬ Comment with your first
printoutput β I read every one. - π Share this with someone who's been meaning to start coding.
Next lesson: Variables β see you there.
The solution
>>> print(Hello)
NameError: name 'Hello' is not defined
>>> Print("hi")
NameError: name 'Print' is not definedReady to try it yourself? Solve General problems with instant feedback in the practice sandbox.
Practice now β


