1.
Introduction to Python
Python is a widely used general-purpose, high level programming language. It was created by Guido van
Rossum in 1991 and further developed by the Python Software Foundation. It was designed with an emphasis
on code readability, and its syntax allows programmers to express their concepts in fewer lines of code.
Python is a programming language that lets you work quickly and integrate systems more efficiently.
There are two major Python versions: Python 2 and Python 3. Both are quite different.
It is used for:
• web development (server-side),
• software development,
• mathematics,
• system scripting.
Python History and Versions
• Python laid its foundation in the late 1980s.
• The implementation of Python was started in December 1989 by Guido Van Rossum at CWI in
Netherland.
• In February 1991, Guido Van Rossum published the code (labeled version 0.9.0) to [Link].
• In 1994, Python 1.0 was released with new features like lambda, map, filter, and reduce.
• Python 2.0 added new features such as list comprehensions, garbage collection systems.
• On December 3, 2008, Python 3.0 (also called "Py3K") was released. It was designed to rectify the
fundamental flaw of the language.
• ABC programming language is said to be the predecessor of Python language, which was capable of
Exception Handling and interfacing with the Amoeba Operating System.
• The following programming languages influence Python:
o ABC language.
o Modula-3
The following table lists all the important versions of Python:
Version Release Date Important Features
Python 0.9.0 February 1991 • Classes with inheritance exception handling
• Functions
• Modules
Python 1.0 January 1994 • Functional programming tools (lambda, map, filter and
reduce).
• Support for complex numbers.
• Functions with keyword arguments
Python 2.0 October 2000 • List comprehension.
Python 2.7.0 - EOL July 2010 • Cycle-detecting garbage collector.
- Jan 2020 • Support for Unicode. Unification of data types and classes
Python 3 December 2008 • Backward incompatible.
Python 3.6 December 2016 • print keyword changed to print() function
Python 3.6.5 March 2018 • raw_input() function depreciated
• Unified str/Unicode types.
• Utilities for automatic conversion of Pytthon 2.x code
Python 3.7.0 May 2018 • New C API for thread-local storage
• Built-in breakpoint()
• Data classes
• Context variables
Python 3.8 October 2019 • Assignment Expression
• Positional-only parameters
• Parallel filesystem cache for compiled bytecode files
Python 3.9 October 2020 • Dictionary Merge & Update Operators
- Current Version • New removeprefix() and removesuffix() string methods
• Builtin Generic Types
Why the Name Python?
There is a fact behind choosing the name Python. Guido van Rossum was reading the script of a popular BBC
comedy series "Monty Python's Flying Circus". It was late on-air 1970s.
Van Rossum wanted to select a name which unique, sort, and little-bit mysterious. So he decided to select naming
Python after the "Monty Python's Flying Circus" for their newly created programming language.
The comedy series was creative and well random. It talks about everything. Thus it is slow and unpredictable, which
made it very interesting.
Python is also versatile and widely used in every technical field, such as Machine Learning, Artificial Intelligence,
Web Development, Mobile Application, Desktop Application, Scientific Calculation, etc.
What can Python do?
• Python can be used on a server to create web applications.
• Python can be used alongside software to create workflows.
• Python can connect to database systems. It can also read and modify files.
• Python can be used to handle big data and perform complex mathematics.
• Python can be used for rapid prototyping, or for production-ready software development.
Why Python?
• Python works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc).
• Python has a simple syntax similar to the English language.
• Python has syntax that allows developers to write programs with fewer lines than some other
programming languages.
• Python runs on an interpreter system, meaning that code can be executed as soon as it is written. This
means that prototyping can be very quick.
• Python can be treated in a procedural way, an object-oriented way or a functional way.
Good to know
• The most recent major version of Python is Python 3. However, Python 2, although not being updated with
anything other than security updates, is still quite popular.
• Python can be written in a text editor. It is possible to write Python in an Integrated Development
Environment, such as Thonny, Pycharm, Netbeans or Eclipse which are particularly useful when managing
larger collections of Python files.
Python Syntax compared to other programming languages
• Python was designed for readability, and has some similarities to the English language with influence from
mathematics.
• Python uses new lines to complete a command, as opposed to other programming languages which often
use semicolons or parentheses.
• Python relies on indentation, using whitespace, to define scope; such as the scope of loops, functions and
classes. Other programming languages often use curly-brackets for this purpose.
3. Python Features
Python provides many useful features which make it popular and valuable from the other programming languages.
It supports object-oriented programming, procedural programming approaches and provides dynamic memory
allocation. We have listed below a few essential features.
1) Easy to Learn and Use
Python is easy to learn as compared to other programming languages. Its syntax is straightforward and much the
same as the English language. There is no use of the semicolon or curly-bracket, the indentation defines the code
block. It is the recommended programming language for beginners.
2) Expressive Language
Python can perform complex tasks using a few lines of code. A simple example, the hello world program you
simply type print("Hello World"). It will take only one line to execute, while Java or C takes multiple lines.
3) Interpreted Language
Python is an interpreted language; it means the Python program is executed one line at a time. The advantage of
being interpreted language, it makes debugging easy and portable.
4) Cross-platform Language
Python can run equally on different platforms such as Windows, Linux, UNIX, and Macintosh, etc. So, we can say
that Python is a portable language. It enables programmers to develop the software for several competing
platforms by writing a program only once.
5) Free and Open Source
Python is freely available for everyone. It is freely available on its official website [Link]. It has a large
community across the world that is dedicatedly working towards make new python modules and functions.
Anyone can contribute to the Python community. The open-source means, "Anyone can download its source code
without paying any penny."
6) Object-Oriented Language
Python supports object-oriented language and concepts of classes and objects come into existence. It supports
inheritance, polymorphism, and encapsulation, etc. The object-oriented procedure helps to programmer to write
reusable code and develop applications in less code.
7) Extensible
It implies that other languages such as C/C++ can be used to compile the code and thus it can be used further in
our Python code. It converts the program into byte code, and any platform can use that byte code.
8) Large Standard Library
It provides a vast range of libraries for the various fields such as machine learning, web developer, and also for
the scripting. There are various machine learning libraries, such as Tensor flow, Pandas, Numpy, Keras, and Pytorch,
etc. Django, flask, pyramids are the popular framework for Python web development.
9) GUI Programming Support
Graphical User Interface is used for the developing Desktop application. PyQT5, Tkinter, Kivy are the libraries which
are used for developing the web application.
10) Integrated
It can be easily integrated with languages like C, C++, and JAVA, etc. Python runs code line by line like C,C++ Java.
It makes easy to debug the code.
11. Embeddable
The code of the other programming language can use in the Python source code. We can use Python source code
in another programming language as well. It can embed other language into our code.
12. Dynamic Memory Allocation
In Python, we don't need to specify the data-type of the variable. When we assign some value to the variable, it
automatically allocates the memory to the variable at run time. Suppose we are assigned integer value 15
to x, then we don't need to write int x = 15. Just write x = 15.
Python Vs C vs C++ vs Java
What is Python?
Python is a high-level, interpreted programming language. It was invented back in 1991, by Guido Van Rossum.
Python is an object-oriented programming language that has enormous library support making the
implementation of various programs and algorithms easy. Its language constructs and object-oriented approach
aim to help programmers to write clear, logical code for various projects.
The biggest strength of Python is its huge collection of standard libraries which can be used for the following:
• Machine Learning
• GUI Applications (like Kivy, Tkinter, PyQt, etc. )
• Web frameworks like Django (used by YouTube, Instagram, and Dropbox)
• Image processing (like OpenCV, Pillow)
• Web scraping (like Scrapy, BeautifulSoup, and Selenium)
• Test frameworks
• Multimedia
• Scientific computing
• Text processing and many more.
What is C
C is a general-purpose, procedural, high-level programming language used in the development of computer
software and applications, system programming, games, web development, and more.
• C language was developed by Dennis M. Ritchie at the Bell Telephone Laboratories in 1972.
• It is a powerful and flexible language which was first developed for the programming of the UNIX operating
System.
• C is one of the most widely used programming languages.
C programming language is known for its simplicity and efficiency. It is the best choice to start with programming
as it gives you a foundational understanding of programming.
What is C++?
C++ is a high-level, general-purpose programming language created by Bjarne Stroustrup in 1979 as an extension
of the C programming language, or “C with Classes”. The language has expanded significantly over time, and
modern C++ has object-oriented, generic, and functional features in addition to facilities for low-level memory
manipulation. Many of the technologies as libraries in Python have underlying C++ code.
Java
Java is a high-level, object-oriented programming language that was originally developed by James Gosling at
Sun Microsystems in 1995. Java has a syntax similar to C and C++ but with low-level difficulties. Java is platform-
independent (WORA – Write Once Run Anywhere) meaning compiled java code can run on different platforms
without recompilation. Java can be used to develop the following applications:
• Desktop GUI Applications
• Mobile Applications
• Artificial intelligence
• Web applications
• Big Data technology
• Gaming applications
• Business applications
Hello world program in C, C++, Java and Python
C: C++:
#include <stdio.h> #include <iostream>
int main() { int main() {
// printf() displays the string // std::cout << "Hello,
inside quotation World!" prints the string
printf("Hello, World!"); inside quotation
std::cout << "Hello, World!";
return 0;
} return 0;
}
To run the C program in Command Line, you can use the
following command: To run the C++ program, you can use the
following command:
gcc hello_world.c -o hello_world
./hello_world g++ hello_world.cpp -o hello_world
./hello_world
Java: Python:
import [Link].*; # This Python program prints
public class HelloWorld { 'Hello, World!'
public static void main(String[] args) print("Hello, World!")
{
// [Link]() prints the
string inside quotation
[Link]("Hello, World!"); To run the Python program, you can use the
} following command:
}
python hello_world.py
To run the Java program, you can use the following
command:
javac [Link]
java HelloWorld
1. Difference Between C vs Python
C Python
An Imperative programming model is basically An object-oriented programming model is
followed by C. basically followed by Python.
Variables are declared in C. Python has no declaration.
Python has OOP which is a part of the
C doesn’t have native OOP.
language.
C Python
Pointers are available in C language. No pointers functionality is available in Python.
C is a compiled language. Python is an interpreted language.
There is a limited number of built-in functions There is a large library of built-in functions in
available in C. Python.
Implementation of data structures requires its It is easy to implement data structures in Python
functions to be explicitly implemented. with built-in insert, append functions.
C is compiled directly to machine code which is Python is firstly compiled to a byte-code and
executed directly by the CPU then it is interpreted by a large C program.
Declaring of variable type in C is a necessary There is no need to declare a type of variable in
condition. Python.
C does not have complex data structures. Python has some complex data structures.
C is statically typed. Python is dynamically typed.
C Python
Syntax of C is harder than python because of which
It is easy to learn, write and read Python
programmers prefer to use python instead of C
programs than C.
C programs are saved with .c extension. Python programs are saved by .py extension.
The assignment gives an error in line. For
An assignment is allowed in a line.
example, a=5 gives an error in python.
In Python, testing and debugging are directly
In C language testing and debugging is harder.
not harder than in C.
C is complex than Python. Python is much easier than C.
The basic if statement in Python is represented
The basic if statement in c is represented as:
as:
if ()
if:
The basic if-else statement in C is represented as: The basic if-else statement is represented as:
if ( ){ if :
C Python
} else:
else {
C language is fast. Python programming language is slow
Python uses indentation to identify separate
C uses {} to identify a separate block of code.
blocks of code.
It is mandatory to mark the end of every statement It is not mandatory to mark the end of every
with a semicolon in C. statement with a semicolon in Python.
2. Difference Between C++ vs Python
The following table shows the key difference between Python and C++ programming languages.
Parameters Python C++
Code Python has fewer lines of code C++ tends to have long lines of code
It uses short-hand syntax and has numerous short-
It has a stiff learning curve as it has lots of
hand structural iterators. It requires ‘self’ as a
predefined syntaxes and structures. C++
parameter to any class instance method. Some of
Syntax uses implicitly ‘this’ to refer to class
the short-hand syntaxes are confusing (e.g.
instances. Some syntax in C++ is extremely
`rkwargs`) but rarely is anything in Python
esoteric.
completely esoteric.
Compilation Python is interpreted C++ is precompiled
It is slower since it uses an interpreter and also It is faster once compiled as compared to
Speed
determines the data type at run time python
Specialized formatting not common in other C-like syntax, powerful OOP features and
Efficiency languages, script-like language, OOP features, code operator overloading, best compile-time
reuse through libraries optimizer
Nature It is dynamically typed. Is statically typed
Python Functions do not have restrictions on the In C++, the function can accept and return
Functions
type of the argument and the type of its return value the type of value which is already defined
Parameters Python C++
Scope of The scope of variables is limited within the
Variables are accessible even outside the loop
Variable loops
C++ programs are saved with the .cpp
Extension Python programs are saved with the .py extension
extension
It has huge community support. When it comes to It also has dedicated followings online. But
Popularity popularity, beginner and novice programmers tend only the people who have some experience
to turn to Python in the field show a lot of interest in C++
Garbage It doesn’t support garbage collection, but it
It supports garbage collection
Collection can be implemented
Rapid Prototyping is possible, but project
Rapid Rapid Prototyping is possible, with easy project
setup can be complicated, live interpreter
Prototyping setup, live interpreter
through IRC bot
Application Web development, data analysis, scientific
Game development, embedded systems, etc
Domain computations, etc
Variable Variables are declared by simply writing their name While declaring a variable it is necessary to
Declaration with their datatype mention its datatype
Parameters Python C++
Installation
on Difficult to install on Windows Easy to install on Windows
Windows
Difference between Python and Java
Parameters Python Java
Python has generally fewer lines
Code Java has long lines of code.
of code.
Compare to JAVA, Python has a
lower number of Frameworks. Java has a large number of Frameworks. Popular ones
Framework
Popular ones are Django and are Spring, Hibernate, etc.
Flask.
The syntax is easy to remember
The syntax is complex as it throws errors if you miss
Syntax almost similar to human
semicolons or curly braces.
language.
Parameters Python Java
Less line no of code, Rapid Self-memory management, Robust, Platform
Key Features
deployment, and dynamic typing. independent
Python is slower since it uses an
Speed interpreter and also determines Java is faster in speed as compared to python.
the data type at run time.
Python’s database access layers
are weaker than Java’s JDBC. This (JDBC)Java Database Connectivity is the most popular
Databases
is why it is rarely used in and widely used to connect with databases.
enterprises.
Machine
Learning Tensorflow, Pytorch. Weka, Mallet, Deeplearning4j, MOA
Libraries
Python has always had a presence Java enjoys more consistent refactoring support than
in the agile space and has grown Python thanks on one hand to its static type system
Practical
in popularity for many reasons, which makes automated refactoring more
Agility
including the rise of the DevOps predictable and reliable, and on the other to the
movement. prevalence of IDEs in Java development.
Parameters Python Java
Multiple Python supports multiple Java partially supports Multiple Inheritance through
Inheritance Inheritance. interfaces.