Python 2.7 – Getting Started

WHY PYTHON

There are lots of languages out there as of 2018 and one question which bothers someone who wants to learn programming is “which language should I learn?”. There is no general agreement on this as people would probably recommend one of the following: C, C++, Java, Python. Most universities also stick to pretty much one of these languages or a combination of these. But even among these few, one has to make a start somewhere with one language. So I feel its Python (others may differ). My reasons are given below:

  • It is a rich and mature language. which is widely used by scientists, academics, colleges and it has a huge repository of libraries and source for for virtually everything from numeric processing to audio programming to databases to websites
  • It has a gentle learning curve. The syntax is easy to understand and there is very little use of brackets and semi-colon delimiters. The only quirk is the horizontal indenting restriction (more on that in the next sections)
  • It is available on all major OS – Windows, Linux, Unix, MacOS to even embedded OS like Raspberry Pi
  • It lends itself easily to scripting quick tools as well as writing huge applications.
  • It is a very contemporary and in-demand language. New and exciting areas like AI, machine learning, computer vision, audio processing etc. all have a strong Python usage.
  • It is a very expressive language i.e you can get a lot done with very little code as compared to other languages

The current version of Python is 3.x . However there is a lot of existing software out there which is in 2.x so I am sticking with 2.7 . There are various differences between Python 3 and Python 2 but they are not very major and at a certain stage later on you can easily transition to Python 3 . Python 2.7 official support will end in the year 2020 so still a few years to go .

INSTALLING PYTHON

This part is quite simple. Just head over to the official downloads page https://www.python.org/downloads/ and the website will automatically detect what OS you are on and give you download options for that platform. It will offer you download options for version 3.x and 2.x Make sure to choose the 2.x option.

For MacOS and Windows, you can download installers which then install Python in your system.

For Linux, if you are using a Debian or a Debian variant like Ubuntu, the following commands should do the trick

# refreshing the repositories
sudo apt update
sudo apt dist-upgrade
# installing python 2.7 
sudo apt install python2.7 python-pip

For Fedora:

sudo dnf upgrade python-setuptools sudo dnf install python-pip python-wheel

For CentOS/RHEL
Enable the EPEL repository using these instructions. On EPEL 6 and EPEL7, you can install pip :

sudo yum install python-pip

On EPEL 7 (but not EPEL 6), you can install wheel:

sudo yum install python-wheel

For OpenSUSE

sudo zypper install python-pip python-setuptools python-wheel


EXECUTING PYTHON CODE

We will be using the command line Python interpreter for all the lessons in the Fundamentals section. Open a command prompt . For Windows users if the Python folder has not been added to the system PATH variable, you will have to navigate to the Python installation folder eg. c:\python2.7 and then run the Python interpreter from there.

So lets load the Python interpreter. Just type python and press Enter

You should see something similar to this:

 

 

 

 

For now just type in

print “Hello World”

and press Enter

That’s it. You have just written your first Python statement. To exit the interpreter type

quit()

In the next post, we will start with understanding Primitive Data Types & Variables.

Be the first to comment

Leave a Reply

Your email address will not be published.


*