This tutorial will show you how to use and install the Python 3 program.
- Windows/Linux/MacOS System
- Internet Access
When installing Python make sure you have a Python 3 version and not Python 2. If Python has been installed on your system already you can check the version number by running
python --version, depending on your system you may need to use
On a Windows system you can install Python from either the Microsoft Store or from the official Python website found here.
Make sure to allow the Python installer to add Python to the PATH.
On a Linux based system most distros will include Python. If it is not installed, or you have the wrong version, you will install Python 3 using your systems package manager for example on a Debian based system you will use apt.
To run Python we will first need to open a terminal/command-prompt. We can then use the
python command, depending on your system the python program may have a different name.
We can run Python in “interactive mode” this allows us to run Python code without making a file.
The output shown below is what happens when we run in this mode. The »> means it is waiting for a Python line to execute.
$ python Python 3.9.6 (default, Jun 30 2021, 10:22:16) [GCC 11.1.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>>
We can then enter a test line which will be:
print("hello World!"). As you can see from the output shown below the line is run and we get the output of “Hello World!”.
Python 3.9.6 (default, Jun 30 2021, 10:22:16) [GCC 11.1.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> print("Hello World!") Hello World! >>>
We can also run a script which will be a file with the .py extension.
First we need to create a file. Here I am using Linux to create a file with the Python script, however this can be done however you want.
$ echo "print(\"Hello World!\")" > hello.py
We can then run this file by giving the first argument of the Python command the file path of the file we want to execute.
When this command is run we should get the following output.
$ python hello.py Hello World!
In this tutorial we have learn how to use the basics of the Python program. The next step is to learn the basics of the Python language, which can be found in my next tutorial here.