The terminal, folders, and your first project
Move around your folders from the terminal, create a project folder, run files, and learn when Python's interactive shell is the right tool.
How do you want to learn?
The problem we are solving
In the last chapter you installed Python and ran a file. But something happened quietly in the middle of it — when you ran the file, the terminal was already open in exactly that folder. VS Code did that for you.
It will not always be like that. When the terminal is in a different folder, you have to go to the file's folder yourself. That "going" is what traps beginners more than anything else. The code is fine, Python is fine, but the terminal is sitting in a different folder — and Python reports that the file does not exist.
At work you will do this a few hundred times a day. So today we turn the terminal from an unfamiliar black screen into a tool you know.
By the end of this chapter you can
- Tell which folder the terminal is currently in
- Move from one folder to another, and step back up one level
- Create a project folder and run a file inside it
- Open and close Python's interactive shell (the REPL)
- Explain how the REPL differs from a
.pyfile — this one confusion wastes a lot of time
Prerequisites: Installing Python and running your first program.
What the terminal actually is
The terminal is a place where you give the computer commands by typing instead of clicking. And every terminal window is always "standing" inside some folder. That folder is called the current directory.
This is the whole idea. When you type python hello.py, what you are really saying is: "run the `hello.py` file in the folder I am standing in right now." If the file is in some other folder, Python will not find it — because it does not look anywhere else.
The commands in this chapter are almost the same in Windows PowerShell, the macOS Terminal and the Linux Terminal. Where they differ, both versions are shown.
Open PowerShell on Windows and you will usually see something like:
PS C:\Users\Rafi>On macOS, something like:
rafi@MacBook ~ %And on Linux, something like:
rafi@laptop:~$This line is called the prompt — the terminal is waiting for your command. On Windows the C:\Users\Rafi part tells you where you are. On macOS and Linux the ~ sign means your home folder.
Four commands that cover the job
pwd — where am I?
pwdIn Windows PowerShell the answer looks like this:
Path
----
C:\Users\RafiOn macOS or Linux you get just the path:
/home/rafi(On macOS the path is /Users/rafi.)
ls — what is in here?
lsIt lists the folders and files. ls works on all three systems; Windows also has an older command for the same job, dir. Running ls before you run a file is a good habit — it confirms the file you are about to run is actually there.
cd — go to another folder
cd python-labTwo dots step one level back up:
cd ..And to go straight back to your home folder from anywhere:
cd ~These three commands work the same way on Windows, macOS and Linux.
Type less. Write the first two or three letters of a folder or file name and press Tab — the terminal fills in the rest. Hand-typing names is the biggest single source of typos, and Tab removes it.
mkdir — make a new folder
mkdir lesson-02Set up a project folder
If you scatter your files across the Desktop while learning, you will not find anything a week later. So pick one place and give each chapter its own folder. In the last chapter you made python-lab in your home folder; now make this chapter's folder inside it:
cd ~
cd python-lab
mkdir lesson-02
cd lesson-02
pwdIf python-lab does not exist yet, run mkdir python-lab after cd ~. These commands are the same on all three systems.
On Windows, that last command should answer:
Path
----
C:\Users\Rafi\python-lab\lesson-02On Linux:
/home/rafi/python-lab/lesson-02On macOS the path starts with /Users/rafi. Your own user name appears where Rafi or rafi is.
Now create a file called notes.py in this folder containing:
print("Folder:", "lesson-02")
print("Squares:", 2 * 2, 3 * 3, 4 * 4)And run it — on Windows:
python notes.pyOn macOS or Linux:
python3 notes.pyFolder: lesson-02
Squares: 4 9 16Python's interactive shell
Type just python in the terminal (python3 on macOS and Linux) and press Enter, and Python itself opens up:
python3Python 3.12.3 (main, Aug 31 2026, 10:18:26) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>The first line will be different on your computer — it shows your Python version, a date, and the name of your operating system (on Windows it ends with on win32, on macOS with on darwin). The >>> sign is the same everywhere, and it means Python is waiting for a line from you. Whatever you write here is answered immediately:
>>> 2 + 3
5
>>> "Python"
'Python'
>>> len("terminal")
8This is called the REPL — Read, Eval, Print, Loop. It is very useful for checking something small: whether a calculation is right, or what a function gives back.
To leave:
>>> exit()The difference that costs people hours: in the REPL, typing2 + 3shows you5on its own. But put only2 + 3in a.pyfile and run it, and nothing appears — Python does the arithmetic, throws the result away, and stays silent. In a file you have to write
When it breaks
python : The term 'python' is not recognized... (Windows) or command not found: python (macOS, Linux) On Windows, Python is not on PATH — see the "When it breaks" section of the previous chapter: re-run the installer and tick the box under Modify. On macOS and Linux the command is called python3.
can't open file '...notes.py': [Errno 2] No such file or directory The terminal is in the wrong folder, or the filename has a typo. Run pwd to see where you are, then ls to see whether the file is there.
cd : Cannot find path ... because it does not exist (Windows) or cd: no such file or directory (macOS, Linux) The folder has not been created yet, or the name is wrong. Create it with mkdir, and press Tab next time you type the name.
The terminal seems stuck, showing only >>> You are inside the REPL, not outside it. ls and python notes.py will not work here — those are terminal commands, not Python. Type exit() to leave.
The folder name has spaces in it Put the whole name in quotes: cd "my python lab". This works on all three systems. Naming folders without spaces avoids the problem entirely, which is why python-lab and my_notes are better habits.
Step 4 of 6 — Predict
Check your understanding
This two-line file is run with python notes.py. What appears in the terminal?
2 + 3
print("done")- Adone
- BNothing — the file raises an error
- C5
- D5 done
The file notes.py is inside the lesson-02 folder, but the terminal is standing one level up, in python-lab. What happens when you run python notes.py?
- APython errors that it cannot open the file — it only looks in the current folder
- BPython searches the subfolders too and runs the file
- CThe file runs, but the output is not shown
- DPython asks you where the file is
Your terminal is showing >>> and you want to list the files in the folder. What do you do?
- AType `print(ls)`
- BClose the terminal window and open a new one; that is the only way
- CType `exit()` to leave the REPL, then run `ls`
- DType `ls` directly — terminal commands work inside the REPL
Answering needs an account
Sign in to check your answers
The questions are above, and working them out in your head is the part that matters. Sign in to see the answers, the explanations and the three-level hints.
Your turn
From the terminal, using commands only:
- Create a folder called
practiceinsidepython-lab - Move into it and confirm with
pwd - Create a file there called
about.pythat prints your name and today's date - Run it with
python about.py(python3 about.pyon macOS or Linux) - Now
cd ..to step back one level and run the same command again — what happened?
That last step is the real lesson. Once you have seen the failure on purpose, you will recognise its cause in one second when it shows up in real work.
There is more in this mission
What you read above is the complete mission — nothing was cut out of it. Pro adds:
- What actually happens underneath — how Python runs this
- The full solution to the exercise, worked step by step
- Harder extra exercises
- The interview question on this topic, with a model answer
Step 6 of 6
Stretch — the chapter quiz
Ten questions from easy to hard. The last ones are difficult on purpose.
Sign in to take the quiz