Hello everyone. After publishing a bunch of articles on advanced level programming using python, we still get a bunch of requests on our facebook page regarding basic programming using python3.
With its popularity rising significantly over the past few years, there are many programmers, both fresh and new, who want to learn python. This tutorial is designed to be a stand-alone introduction to python, even if you have never programmed before. However, if you are already familiar with any other programming language like C or C++, you will be able to relate to various concepts much easily. By the end of this article, you will have some idea about how python programming works and be able to write your own python program.
Introduction to python
Python is an interpreted high-level programming language for general-purpose programming. Interpreted meaning the instructions are not directly executed by the target machine, but instead read and executed by some other program (in our case, the python interpreter). And high level because the python codes are closer to human language and further from machine language as we will see later.
The next question on your mind might be what does general-purpose programming include? The answer is almost everything. Numerical Computing, Data Analysis, Web Development, Game Development, Web Scraping, Deep Learning, Computer Vision are some application areas of python programming language.
Currently, there are two major versions of python in use. Python2.7 and Python3. And it sucks that python3 does not have backward compatibility. Meaning the code you wrote in python2.7 will not run using the python3 interpreter. However, since the End Of Life date for python2.7 is in the year 2020, meaning the official support for the version will end in that year, we will concentrate our focus towards python3.
Getting set up – Installing python on your machine
For the latest versions of Mac OS and Linux machines, you don’t need to do anything. Yes, nothing. Both the Mac OS and various popular distributions in Linux are shipped with python installed. You can try it out by typing the command python3 on your bash shell or terminal. It should open up a prompt like one shown below:
Even if it doesn’t don’t worry. You can refer to our article, Install Python3.6 on Ubuntu. Windows by default does not come with python interpreter pre-installed. But the process of installing python3 on windows is fairly simple. You can refer to our another article, Python 3.6 download and install for windows to install the python interpreter if you are on a windows machine.
Running python script on your machine
There are two ways to run a python command. We are going to make the classic “Hello World!” program as our first python program.
Open up the python terminal by typing the command python3 on your terminal (if you are using Linux or MacOS) or command prompt (if you are using Windows) and type
Open up a text editor of your choice and type print("Hello World!") Save the file with a .py extension. I’ll just save it as example.py. Navigate to the location of the file using terminal or command prompt and type
Congratulations! You have just written your first python program. It’s that easy. “print” is a function in python3 that is used to write into the standard output. In our next article we will look at the python3 print function in detail.