Python

Python is a simple and elegant programming language. Python is easy to learn and its syntax is simple to understand. Python has gained a lot of popularity in the last few years – all thanks to its frameworks in Machine Learning, Deep Learning, and Artificial Intelligence space.


According to Google Trends, Python is more popular than Java now in the United States. Sometime in the last couple of years, interest in Python surpassed the interest in Java programming language.

Python Popularity Google Trends
Python vs Java Popularity

Note: If you check the Google Trends stats for Worldwide countries, both Java and Python have almost the same popularity. However, the interest in Python has been growing rapidly from 2016 onwards.

Python popularity worldwide
Python Popularity – Google Trends

History of Python

Before we start with Python programming, let’s have some idea about the history of Python programming.

Who is the creator of Python?

Python programming language was created by Guido van Rossum. Its implementation started in 1989 and the first version was released in 1991.


What’s the inspiration?

Python was developed as a “hobby” programming project by Guido van Rossum around December 1989. It was written as an interpreter and a descendant of ABC language that would appeal to Unix/C hackers. The goals of Python programming are:

  1. Easy and intuitive language, yet powerful enough to be used in multiple domains.
  2. Open source and free for everyone to use, improve and extend. The python source code is available on GitHub.
  3. Simple and English-like code that anybody can understand and associate easily.
  4. Suitable for quick development and short turn-around time.

Why named Python?

Guido van Rossum was a big fan of Monty Python’s Flying Circus. Monty Python was a British comedy group and the name “Python” was chosen as a tribute to this. It reflects the philosophy of Python to keep it fun and interesting for programmers.


What is Zen of Python?

The Zen of Python is the collection of 19 software principles that guide the Python development. This is part of PEP-20 and you can read these principles here.


Official Links

  1. Official Documentation
  2. The Python Software Foundation
  3. Python Package Index
  4. Python Source Code – GitHub
  5. Python Enhancement Proposals (PEPs)

What is the Python Programming Language?

Python is a multi-paradigm programming language. Python support Object-oriented programming (Classes, Objects) and structured programming (if-else, for-while). Many of its features support functional programming (itertools, functools) and aspect-oriented programming (aspectlib).

Python is open-source and highly extendable. Many popular open-source frameworks for different areas such as Graphs, Scientific Calculations, Machine Learning, Artificial Intelligence, etc. are built on top of Python programming language.


Why learn Python Programming?

Some of the benefits of Python programming language are:

  1. Simple and English Language Syntax
  2. Quick start and easy to learn
  3. Open Source and Free to extend
  4. Vast community support. There are over a million questions in StackOverflow Python category.
  5. Python is portable
  6. Easy to extend and work with other programming languages
  7. Tons of free modules and packages to help in every aspect of development

What can we build from Python Programming?

There are no limitations on what can be built using Python. However, some of the popular areas where Python is used are:

  1. Standalone Utility apps
  2. Web Applications
  3. Data Science Applications
  4. Deep Learning
  5. Machine Learning
  6. Artificial Intelligence
  7. Scientific and Numerical implementations
  8. Embedded Programming
  9. Raspberry PI apps
  10. Graphs and Charts
  11. Game Development

Installation

We can install Python on every popular operating system. Most of the times, we use Windows, Linux or Mac OS. In this section, we will learn how to install Python on these operating systems.


Install Python on Windows

Let’s go ahead and install Python on Windows 10. The current python stable version is 3.7 and 3.8 is about to be released. The below steps might be slightly different if you are installing any other version. But, overall they will be the same for every version.

Step 1: Go to the Python Releases for Windows Official Website.

Step 2: In the “Stable Releases” section, click on the “Download Windows x86-64 executable installer“. If your Windows is 32-bit, then click on “Download Windows x86 executable installer“. This will download the Python installer executable file.

Python releases for Windows 64-bit and 32-bit installers download.

Step 3: Run the installer file. If you get any warnings, ignore that and click on “Run” button. You should see the setup window.

Step 4: Make sure to check the “Install launcher for all users” and “Add Python 3.7 to PATH” boxes. Then click on the “Install Now” button. If you get a popup window asking if you want the app to make changes to your system, click on the “Yes” button.

run python windows installer exe file
python windows installer app update permission allow

Step 5: You should get the “Setup was successful” window after Python is installed.

Python windows installer setup progress.
python windows setup successful message window popup

Step 6: It’s time to verify that Python is installed properly. Open “Command Prompt” and type “python –version” command. The output should display the installed python version. We are able to run python from the command line because it’s present in the PATH variable. In case you missed to check the “Add Python 3.7 to PATH” box, you can add them manually to run python from the command prompt.

python windows version command prompt
Python PATH environment variable settings

Step 7: You can also run “python.exe” to start the Python command line interpreter tool. It’s located in “C:\Users\{USER_HOME}\ AppData\Local\Programs\ Python\Python37\” directory.

python cli tool windows

Step 8: Python provides Integrated Development and Learning Environment tool, which is called IDLE. You can run “C:\Users\{USER_HOME}\ AppData\Local\Programs\ Python\Python37\Lib\idlelib\idle.pyw” to start it and execute python code snippets.

Python Windows IDLE app
Python Windows IDLE App

Install Python on Linux (Ubuntu)

We can use “apt” to install Python on Ubuntu. It’s a single line command and works on any Debian system. You should have the Sudo access to install Python.

root@mailer9:~# sudo apt install python3.7
Reading package lists... Done
Building dependency tree       
Reading state information... Done
...
After this operation, 22.4 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
...
Setting up python3.7 (3.7.1-1~18.04) ...
root@mailer9:~# python3.7 --version
Python 3.7.1
root@mailer9:~#
Python Install Ubuntu
Python Install Ubuntu 18.04 LTS

Install Python on Mac OS

Step 1: Go to the Python Releases for Mac OS X Official Website.

Step 2: From the “Stable Releases” section, click on “Download macOS 64-bit installer” to download the installer file. Mac OS runs on 64-bit OS but if you have changed it to 32-bit, then click on “Download macOS 64-bit/32-bit installer” link.

Python Mac Os X Installer Download
Python Mac Os X Installer Download

Step 3: Run the Python installer package. It will bring the following screen. Click on the “Continue” button and follow along with the setup instructions.

Install Python Mac Os Screen
Install Python Mac OS Screen
Install Python Mac Os Read Me Screen
Install Python Mac Os Read Me Screen
Python Mac Os Installer License Screen
Python Mac Os Installer License Screen
Python Mac Os Installer Agree Licence
Python Mac Os Installer Agree Licence
Python Mac Os Installer Information
Python Mac Os Installer Information
Python Install Mac Os User Password
Python Install Mac Os User Password
Python Mac Os Successful Installed
Python Mac Os Successful Installed
Python Installer Mac Os Move To Trash
Python Installer Mac Os Move To Trash

Step 4: It’s time to verify that Python is installed successfully. Open the Terminal window and run the following command. It should print the python version you have installed in the previous step.

$ python3.7 --version
Python 3.7.3
$ 

Setting up Python IDE – PyCharm

Python interpreter and IDLE app are good to run simple scripts. But, if you want the ease of development then you should use a Python IDE. PyCharm from JetBrains is the most popular Python IDE. It has a Community Edition, which is free and open source. Let’s go ahead and set up PyCharm IDE before we start with our first Python program.

NOTE: I am using Mac OS, so below steps might be slightly different for other operating systems.

Step 1: Go to PyCharm Official website download page and click on macOS button. Then click on the “Download” button for Community Edition. It will download the PyCharm installer DMG file for Mac OS.

Pycharm Download Community Edition
Pycharm Download Community Edition

Step 2: Run the PyCharm DMG file. It will open the installer. Now, drag and drop the “PyCharm CE” app to the “Applications” directory.

PyCharm CE App Drop To Applications Directory
PyCharm CE App Drop To Applications Directory

Step 3: Open the PyCharm app from the Applications folder. You might get an alert saying “PyCharm CE.app is an app downloaded from the Internet. Are you sure you want to open it?” Go ahead and click on “Open” button.

Step 4: If you had installed PyCharm earlier, it will ask if you want to import the settings from the earlier version. If it’s a fresh installation, then the configuration window will open where you can set up PyCharm settings. Go through the configuration settings and finally PyCharm Welcome screen will open.

PyCharm Setup Mac OS Keymap Scheme
PyCharm Setup Mac OS Keymap Scheme
PyCharm UI Theme Options
PyCharm UI Theme Options
PyCharm Launcher Script
PyCharm Launcher Script
PyCharm Features Plugins
PyCharm Features Plugins
PyCharm Welcome Screen
PyCharm Welcome Screen

Step 5: Let’s create our first PyCharm project. Click on the “Create New Project” button on the PyCharm welcome screen as shown in the above image.

Step 6: Provide the directory where the project will be created. Then click on the “Create” button.

PyCharm New Project Location
PyCharm New Project Location

Step 7: The project will be created and the project explorer window will open. If there is a directory “venv” present in the project, don’t worry about it. It’s a virtual environment created by PyCharm so that your project settings are not affected by other project settings.

Step 8: It’s recommended to create different directories to create python scripts. You can create them based on their usage. For example, util directory for utility scripts. Right-click on the Project and click on the “New > Directory” link. It will open a new popup window. Enter the directory name and click on the “Ok” button to create the new directory.

PyCharm Project New Directory
PyCharm Project New Directory

First Python Program

We have already installed Python and PyCharm IDE. We have also created a new PyCharm project and a directory. Now it’s time to create our first python program.

Step 1: Right-click on the project directory and click on “New > Python File” link. Provide the file name as “hello_world” in the popup window and click on the “Ok” button.

PyCharm Create New Python File
PyCharm Create New Python File

Step 2: At this point, you will have an editor window with the empty python script you just created. Let’s add some python code to print some message on the terminal. You can copy-paste the below script to this file and save it.

print("Welcome to Python Programming Tutorials")

Step 3: Right-click on the python file editor. Then click on “Run hello_world” link to run the python script.

PyCharm Run Python Script
PyCharm Run Python Script

Step 4: You can verify the output printed on the PyCharm run screen.

PyCharm Python Script Hello World Output
PyCharm Python Script Hello World Output

Step 5: Python scripts can be executed from the command line too. Let’s see how to run our hello world script from the terminal.

$ cd /Users/pankaj/Documents/PycharmProjects/PythonTutorialPro/hello-world 
$ ls
hello_world.py
$ python3.7 hello_world.py 
Welcome to Python Programming Tutorials
$ 
Running Python Script From Command Line
Running Python Script From Command Line

That’s all for running our first python program. We learned how to execute it from PyCharm IDE and terminal.


Conclusion

Python is one of the most popular programming languages. We learned about the history of Python programming. We also learned how to install Python on Windows, Linux, and Mac OS. We also installed PyCharm IDE to work with python programming easily. Finally, we created our first hello world python script and executed it from PyCharm as well as the command line.