Introduction to Python

Updated on May 22, 2019
Sam Shepards profile image

I'm a software developer with a great interest in data analysis and statistics.

Python is a very popular high-level programming language that supports multiple programming paradigms. You use it for object-oriented, functional, procedural, imperative and reflective programming.

It was created by Guido Van Rossum as a pet project during the late 1980s and early 1990s. Initially, Python was not open-source, but later the source code for Python was released under the GNU GPL license.

Over the last 26 years, the language has evolved a lot. There are two major flavors of the language:

  • Python 2.x
  • Python 3.x.

Python 2.0 was released in the year 2000. It had major features like support for Unicode and a nice garbage collector for optimal memory management. Python 3.0 was released in 2008, but it is not backward compatible with Python 2.0.

To make sure that the features of Python 3.x are available for Python 2.x, various releases of the latter were done after the first release of the former with some features backported to 2.x versions.

These changes were done in phases so that code written in Python 2.x could be easily run using Python 3.x before the "end of life" of Python 2.x is reached.

Features of the Python Programming Language

Since the language uses English keywords frequently and defines scope based on indentation, code written in Python is highly readable. Some of the salient features of the language are:

Interpreted and interactive language

Python interprets the code at runtime. It supports writing code directly onto the interpreter console. Alternatively, we can add our code into a Python module and feed that file as input to interpreter. A Python module is a file with .py extension that contains code written in Python. For instance, if you have a file named Test.py, we can run the code using:

python Test.py

The output for the above code will be printed to the console.

Supports many paradigms

Python supports creating Objects that encapsulate code. But it is possible to write code that consists of functions only and no objects and you can still run the code.

Easy to learn

Python has few keywords and is a complete beginner’s programming language. The syntax is clearly defined and simple, making it easier for a newbie to learn it.

Better readability and maintainability

Unlike other programming languages like C, C++, Java, etc, the scope of code is not defined using curly braces. Instead, it is defined by indentation. This should ensure that developers can read through the code without much effort.

I don't agree that much with this. Most people using other languages like Java also structure their code for readability and use indentation. The curly braces make it a little more verbose maybe, but it's still very readable.

For example, a simple for loop in Java to iterate over a list of strings and print each of them would be:

for(String s: strList) {
    System.out.println(s);
}

In case of Python, the same piece of code will be written as follows:

for s in strList:
    print(s)

Note that if the print(s) line is treated as a separate statement outside for loop if the indentation is not proper. This makes sure that code will be readable at the end.
Python code can be organized properly and spaghetti code can be avoided. This adds to better maintainability of code written using Python.

Availability of a standard built-in library

A very broad built-in library is available for the language. The library files are again written in Python. These files can be found under /Lib.

Portable

Code written using an interpreter on a Windows machine is runnable on a Linux or Mac environment

Extendable

It is possible to add low-end modules to the language as add-ons for specific applications making it easier for developers to customize tools available with the language.

Scalable

It supports a large number of files than shell scripting.

Uses for Python

Some of the major areas in which Python is used are:

Application Programming

Since the language is scalable, Python was the language of choice for building many applications – be it for desktop, small devices or cloud.

Database and GUI programming

Python provides interfaces for almost all major databases and supports creation of GUI tools that can be run in Windows, Linux or Mac OS.

Scripting

Python is used for scripting while building large applications with scale out architecture.

Testing

Python is used to build test frameworks that can be integrated with Continuous Integration Builds in many large organizations. Tools like Robot Framework can be used for this purpose.

Cloud computing

Since the language is scalable, it is used in cloud computing. A very good example would be OpenStack which is a cloud based operating system fully written using Python.

Setting Up The Python Development Environment

To install, we need to download the binaries or the installers from the official Python website Link: https://www.python.org/downloads/ depending on the operating system that we use.

Installation and Set Up on Windows

Download and install Python as indicated in the previous section. After installation. access system properties.

Under the "Advanced" tab of the System Properties dialog box, click on Environment Variables.

Click on the system variable named Path and Select Edit.

Add the path to python installation folder here and save it.

Open a new command prompt window and type python. It should show Python interpreter console where we can directly add the code.

Installation and Set Up on Linux

In Linux, the .bashrc file can be edited to include the following:

export pyhome=/usr/bin/python
export path=$path:$pyhome

After saving the environment variables and logging in again, simply typing python onto a new terminal should launch the python interpreter console where we can directly write code.

Python Development Using Eclipse

Since Python is an interpreted language, we can directly code into the interpreter console and see the output for each statement that we add into the console.

To develop large applications, we may want to use another application for ease of organizing the code and working with multiple files. The application can be a text editor like Notepad++ or Sublime Text. It can also be an IDE like Eclipse or IntelliJ.

Let us see how Eclipse can be used for Python development.

Prerequisites

The latest PyDev plugin available in Eclipse Marketplace works with Eclipse Oxygen and Eclipse Neon. It would also be great if JRE 1.8 is installed as Eclipse uses javaw.exe available in JRE folder for running the application.

Installing Pydev in Eclipse IDE

On the Eclipse menu bar, select Help -> Eclipse marketplace.

Search for Pydev in Eclipse Marketplace and choose install.

Follow the steps in the next few windows, accept the license agreement and select all the features as follows to install.

After installation, we need to add python interpreter to Eclipse preferences so that python code can be run in the console.

After the path is set correctly, the preferences should look as follows:

Create Our First PyDev Project

Let us create our first Python project in eclipse.

Add a new package to the project.

Create a new .py file under the package.

Add the following code to the new python file:

print("Hello World!")

The new Python file can be run by simply right-clicking on the editor window and selecting Run As -> Python Run.

This should print “Hello World!” to the console.

© 2019 Shepards

Comments

    0 of 8192 characters used
    Post Comment

    No comments yet.

    working

    This website uses cookies

    As a user in the EEA, your approval is needed on a few things. To provide a better website experience, turbofuture.com uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

    For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at: https://turbofuture.com/privacy-policy#gdpr

    Show Details
    Necessary
    HubPages Device IDThis is used to identify particular browsers or devices when the access the service, and is used for security reasons.
    LoginThis is necessary to sign in to the HubPages Service.
    Google RecaptchaThis is used to prevent bots and spam. (Privacy Policy)
    AkismetThis is used to detect comment spam. (Privacy Policy)
    HubPages Google AnalyticsThis is used to provide data on traffic to our website, all personally identifyable data is anonymized. (Privacy Policy)
    HubPages Traffic PixelThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized.
    Amazon Web ServicesThis is a cloud services platform that we used to host our service. (Privacy Policy)
    CloudflareThis is a cloud CDN service that we use to efficiently deliver files required for our service to operate such as javascript, cascading style sheets, images, and videos. (Privacy Policy)
    Google Hosted LibrariesJavascript software libraries such as jQuery are loaded at endpoints on the googleapis.com or gstatic.com domains, for performance and efficiency reasons. (Privacy Policy)
    Features
    Google Custom SearchThis is feature allows you to search the site. (Privacy Policy)
    Google MapsSome articles have Google Maps embedded in them. (Privacy Policy)
    Google ChartsThis is used to display charts and graphs on articles and the author center. (Privacy Policy)
    Google AdSense Host APIThis service allows you to sign up for or associate a Google AdSense account with HubPages, so that you can earn money from ads on your articles. No data is shared unless you engage with this feature. (Privacy Policy)
    Google YouTubeSome articles have YouTube videos embedded in them. (Privacy Policy)
    VimeoSome articles have Vimeo videos embedded in them. (Privacy Policy)
    PaypalThis is used for a registered author who enrolls in the HubPages Earnings program and requests to be paid via PayPal. No data is shared with Paypal unless you engage with this feature. (Privacy Policy)
    Facebook LoginYou can use this to streamline signing up for, or signing in to your Hubpages account. No data is shared with Facebook unless you engage with this feature. (Privacy Policy)
    MavenThis supports the Maven widget and search functionality. (Privacy Policy)
    Marketing
    Google AdSenseThis is an ad network. (Privacy Policy)
    Google DoubleClickGoogle provides ad serving technology and runs an ad network. (Privacy Policy)
    Index ExchangeThis is an ad network. (Privacy Policy)
    SovrnThis is an ad network. (Privacy Policy)
    Facebook AdsThis is an ad network. (Privacy Policy)
    Amazon Unified Ad MarketplaceThis is an ad network. (Privacy Policy)
    AppNexusThis is an ad network. (Privacy Policy)
    OpenxThis is an ad network. (Privacy Policy)
    Rubicon ProjectThis is an ad network. (Privacy Policy)
    TripleLiftThis is an ad network. (Privacy Policy)
    Say MediaWe partner with Say Media to deliver ad campaigns on our sites. (Privacy Policy)
    Remarketing PixelsWe may use remarketing pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to advertise the HubPages Service to people that have visited our sites.
    Conversion Tracking PixelsWe may use conversion tracking pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to identify when an advertisement has successfully resulted in the desired action, such as signing up for the HubPages Service or publishing an article on the HubPages Service.
    Statistics
    Author Google AnalyticsThis is used to provide traffic data and reports to the authors of articles on the HubPages Service. (Privacy Policy)
    ComscoreComScore is a media measurement and analytics company providing marketing data and analytics to enterprises, media and advertising agencies, and publishers. Non-consent will result in ComScore only processing obfuscated personal data. (Privacy Policy)
    Amazon Tracking PixelSome articles display amazon products as part of the Amazon Affiliate program, this pixel provides traffic statistics for those products (Privacy Policy)
    ClickscoThis is a data management platform studying reader behavior (Privacy Policy)