In this part 2 of the tutorial, we will:

Let's first set up python first

Python is a language that finds use in nearly every domain possible. Its official website will give you an overview of this. In addition, its simplicity, as well as the way it ensures tasks can be performed using fewer lines of code, is encouraging many developers across the world to take it up.

Currently, there are two common versions of Python: Version 2 and 3 and later. Apart from some syntactical differences, they are pretty similar. As support for version 2 would fade over time, our course supports version 3.

 

How to Install Python on macOS

Follow these steps to download the full installer:

  1. Open a browser window and navigate to the Python.org Downloads page for macOS.

  2. Under the “Python Releases for Mac OS X” heading, click the link for the Latest Python 3 Release - Python 3.x.x. As of this writing, the latest version was Python 3.8.4.

  3. Scroll to the bottom and click macOS 64-bit installer to start the download.

  4. Run the installer.

Verify your installation by executing the below command in your terminal.

$ python3 --version
Python 3.6.10

 

How to Install Python on Windows

Follow these steps to download the full installer:

  1. Open a browser window and navigate to the Python.org Downloads page for Windows.

  2. Under the “Python Releases for Windows” heading, click the link for the Latest Python 3 Release - Python 3.x.x. As of this writing, the latest version was Python 3.8.4.

  3. Scroll to the bottom and select either Windows x86-64 executable installer for 64-bit or Windows x86 executable installer for 32-bit.

  4. Be sure to check the box labeled "Add Python to PATH"
  5. When the installer is finished downloading, run it by double-clicking on the downloaded file.

 

How to Install Python on Ubuntu

Depending on the version of the Ubuntu distribution you run, the process for setting up Python on your system will vary. You can determine your local Ubuntu version by running the following command:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.4 LTS
Release:        16.04
Codename:       xenial

Follow the instructions below that match the version number you see under Release in the console output:

  • Ubuntu 18.04, Ubuntu 20.04, and above: Python 3.8 doesn’t come by default on Ubuntu 18.04 and above, but it is available in the Universe repository. To install version 3.8, open a terminal application and type the following commands:

    $ sudo apt-get update
    $ sudo apt-get install python3.8 python3-pip
    

    Once the installation is complete, you can run Python 3.8 with the python3.8 command and pip with the pip3 command.

  • Ubuntu 17 and below: Python 3.8 isn’t in the Universe repository, so you need to get it from a Personal Package Archive (PPA). For example, to install from the “deadsnakes” PPA, use the following commands:

    $ sudo add-apt-repository ppa:deadsnakes/ppa
    $ sudo apt-get update
    $ sudo apt-get install python3.8 python3-pip
    

    Once the installation is complete, you can run Python 3.8 with the python3.8 command and run pip with the pip3 command.

 

Now let's install a code editor for python

You can install any one of the below.

 

How to execute or run a python script?

  • Create a file and name it app.py. Instead of the app, you can name it anything you wish.
  • Open your terminal or command prompt at the same directory where you have created the file.
  • Now to execute the file you have to just write the command below and press enter.
  • python app.py

 

Writing first python program

Open app.py and write the below code.

print("Welcome to python 3 tutorial series")

First, let's understand what is written here print is a python function to print something, and inside the print function there is a text enclosed within " " is a string. Any string inside the print function will be printed on the screen.

Now run the script using the command python app.py

As you can see the string is printed on your screen.