Getting Started with Python Programming: A Comprehensive Guide

O

Ohidur Rahman Bappy

MAR 22, 2025

Introduction

Python is a versatile, high-level, interpreted programming language that has gained immense popularity due to its simplicity and powerful capabilities. Initially created by Guido van Rossum in 1985, Python continues to evolve with its latest versions bringing more efficient features.

History

Python's journey began with its influence from several languages such as ABC, Modula-3, C, C++, Algol-68, SmallTalk, and Unix shell, among others. It was officially released as:

  • Python 1.0 in November 1994.
  • Python 2.0 in 2000, with Python 2.7.11 being its last edition.
  • Python 3.0 in 2008, emphasizing cleaner syntax and eliminating redundancy.

Python's development is now managed by a core team, with Rossum still playing an essential advisory role.

Python Characteristics

  • High-Level: Easy to use and read.
  • Interpreted: Executes code line-by-line at runtime.
  • Interactive: Supports command-line interactions.
  • Object-Oriented: Supports procedural, structured, and OOP principles.
  • Dynamic Typing: Features dynamic data typing and checking.
  • Garbage Collection: Automatically manages memory allocation.
  • Integration: Seamlessly integrates with other languages and tools.
  • Portability: Works across platforms easily.

Applications

Python finds use in various domains including:

  • Scripting
  • Graphical User Interfaces (GUI)
  • Databases
  • Web Development
  • Machine Learning
  • Computer Vision
  • Automation

Python 2 vs Python 3

Print Statement

In Python 3, print is a function requiring parentheses.

# Python 2
print "Hello World"

# Python 3
print("Hello World")

Input Function

Python 3 employs input() for string inputs, replacing the deprecated raw_input() from Python 2.

# Python 2
x = input('something:') 

# Python 3
x = input("something:")

Integer Division

Python 2 performs floor division for integers, while Python 3 performs true division by default.

# Python 2: results 1
a = 3 / 2

# Python 3: results 1.5
a = 3 / 2

Unicode Strings

Strings are Unicode by default in Python 3, simplifying text processing.

Range Function

Python 3 replaces xrange() with range(), which now supports slicing.

Exception Handling

In Python 3, use the as keyword for exception handling.

# Python 2
except Exception, e:

# Python 3
except Exception as e:

Converting Python 2 Code to Python 3

To update your Python 2 code, you can use the 2to3 utility:

2to3 -w your_script.py

Installation

On Windows

Download the binary installer from the official Python website.

On Linux

Install Python 3 using the package manager:

sudo apt-get install python3-minimal

From Source on Linux

wget https://www.python.org/ftp/python/3.5.1/Python-3.8.1.tgz
tar xvfz Python-3.8.1.tgz
cd Python-3.8.1
./configure --prefix=/opt/python3.8.1
make
sudo make install

Setting Up PATH

Configure your system to recognize the Python installation path by adjusting the environment variable.

Unix/Linux

# csh shell
setenv PATH "$PATH:/usr/local/bin/python3"

# bash shell
export PYTHONPATH="/usr/local/bin/python3.8"

Windows

# Command Prompt
path %path%;C:\Programs\python3

Conclusion

With this guide, you are now equipped to start your Python journey. Understanding the transition from Python 2 to Python 3 and setting up your environment correctly are crucial steps to harnessing the full potential of Python programming.