Enchanted Code

Python 3 First Usage

3 minutes read

Intro

This tutorial will show you how to use and install the Python 3 program.

Requirements

  • Windows/Linux/MacOS System
  • Internet Access

Installation

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 python3 --version.

Windows

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.

Linux

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.

MacOS

On a MacOS system it can be installed from the official Python website found here. Or you can install it using brew for example: brew install [email protected].

Running

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.

Interactive Mode

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.

1
2
3
4
5
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!”.

1
2
3
4
5
6
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!
>>>

Script Mode

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.

1
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.

1
2
python hello.py
Hello World!

Conclusion

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.

See Also

Buy Me A Coffee