Tutorials / Python from Scratch / Installing Python 3.13 and running your first script

Installing Python 3.13 and running your first script

12 min read python
Course contents (15 lessons)
  1. Getting started
  2. Installing Python 3.13 and running your first script
  3. Variables and basic data types
  4. Text, numbers and user input
  5. Working with strings
  6. Numbers and arithmetic
  7. Input and output: talking to the user
  8. Making decisions and repeating work
  9. Making decisions with if, elif and else
  10. Loops: for, while, break and continue
  11. Collections of data
  12. Lists and tuples
  13. Dictionaries and sets
  14. Functions and modules
  15. Writing your own functions
  16. Modules, pip and virtual environments
  17. Files and errors
  18. Reading and writing files
  19. Errors and exceptions
  20. Final project: expense tracker
  21. Project: build the expense tracker, part 1
  22. Project: summaries, search and improvements

What Python is, and why start here

Python is a general purpose programming language. People use it for automation scripts, websites, data work and machine learning. It is popular with beginners because the code reads almost like English and you can see results quickly.

In this course we use Python 3.13. Everything here also works on 3.12 and 3.14, so do not worry if your version is a little different.

Installing Python

Windows

Go to python.org, open the Downloads page and get the latest Windows installer. Run it. On the first screen there is a checkbox called Add python.exe to PATH. Tick it. This is the step people miss most often, and without it your terminal will not find Python.

macOS

Download the macOS installer from python.org and run it. If you use Homebrew, brew install python@3.13 does the same job.

Linux

Most distributions already include Python 3. Check the version first. If it is older than 3.12, install a newer one with your package manager or with a tool such as pyenv.

Check that it works

Open a terminal. On Windows that is PowerShell or Windows Terminal. Type this:

python --version

On macOS and Linux the command is often python3 --version. You should see something like Python 3.13.1. If you see "command not found", the PATH step above is the likely cause. Close the terminal and open a new one, because the old one does not see the changed settings.

The interactive prompt

Type python and press Enter. You will see >>>. This is the REPL, a place where Python runs each line as you type it. It is great for small experiments.

>>> 2 + 3
5
>>> "hello" * 3
'hellohellohello'
>>> exit()

I still use the REPL every day to check a small idea before I put it in a real file.

Your first script

The REPL forgets everything when you close it. Real programs live in files. Make a folder called python-course, open it in any text editor (VS Code is a good free choice) and create a file named hello.py.

# hello.py
name = "Ghulam"
print("Hello, " + name + "!")
print("Python is working.")

Save the file. In the terminal, go to the folder and run it:

cd python-course
python hello.py

The output is:

Hello, Ghulam!
Python is working.

What the script does

The first line starts with #. That is a comment. Python ignores it, and it is there for humans. The second line creates a variable called name and stores the text "Ghulam" in it. We will cover variables in the next lesson. The print function shows text on the screen. The + joins two pieces of text together.

Python runs a file from the top to the bottom, one line at a time. That simple rule explains a lot of behaviour you will see later.

Common mistakes

  • Saving the file as hello.py.txt. Windows hides known extensions by default. Turn on "File name extensions" in Explorer and check.
  • Running the command inside the REPL. If you see >>> and type python hello.py, you get a syntax error. Type exit() first.
  • Being in the wrong folder. The error "can't open file" nearly always means your terminal is in a different directory from your script.
  • Mixing up quotes. "hello" and 'hello' both work. Starting with one kind and ending with the other does not.

Reading an error message

You will see errors often. That is normal, and I still get them every day. Python prints the file name, the line number and a description. Always read the last line first. It tells you what went wrong, such as SyntaxError or NameError. Then look at the line number it points to.

Try it yourself

Create a file called about_me.py. Use three print calls to show your name, your city and one thing you want to build with Python. Run it from the terminal. Then change one of the lines on purpose to remove a closing quote, run it again, and read the error message.

python
# hello.py
name = "Ghulam"
print("Hello, " + name + "!")
print("Python is working.")

This course is free to read. Create a free account to enrol, save your progress and pick up where you left off.

Sign up free I already have an account