Python 1.4 - Strength/Features of Python

 

Strength/Features of Python

Python has become very popular in the recent past because of its Easy syntax, very easy to learn and understand, readability of code and dynamically typed programming language. Python is giving very tough competition to its competitors such as Java. Following are the features of python –

1.   Readability

Python is very simple programming language. When we read a Python program, we feel like reading English sentences. If you are familiar with C or Java, then you would know that these languages use curly braces for block of code but python uses indentation for block of code that makes it very easy to read and understand.

2.   Easy to learn

Python has very easy syntax as compared to other languages. Learning Python is extremely easy. If you have good knowledge of C, then Python is equal to the game for you since Python resembles C language.

3.   Dynamically typed

This is Python’s most powerful feature. In Python, we need not declare anything to store any value. If we want to store values, then we can just use an assignment operator. For example, we can write a statement to store value 20 into variable ‘x’ such as ‘x =20’. We do not need to worry about the data type. Later we can store anything else into variable ‘x’ and later we can also store anything else into ‘x’ i.e. we can store different values into variable ‘x’ at any time without specifying data type. This feature is known as Dynamically typed. Python dynamically finds out the type of data at run time. Languages like C and Java are statically typed. In these languages, the variable names and datatypes should be mentioned properly. Attempting to store different type of value to a variable triggers error or exception. Let’s clear your doubt, if so –

Python statements (Dynamically typed) –

 

x = 20 # stored number 20 into variable ‘x’ without specifying its datatype

x = ‘a’ # then stored character ‘a’ into ‘x’

x = ‘India’ # then stored a string ‘India’

x = 5.5 # then stored a float number (with decimal point) 5.5 into x

 

C statements (Statically typed) –

 

int x=20; // stored number 20 into variable ‘x’ (specified the datatype ‘int’)

x = ‘a’ // Error   

x = “India” // Error

x = 5.5 // Error   

 

As you can see, in Python we do not need to declare type of variable x before storing any value.

But in C, we had to declare type of variable x before storing any value.

4.   Machine independent

When Python code is compiled, we get the Byte code. The byte code is independent of machine. The byte code can be run on any machine, no matter if the machine is running on Windows, Linux or Mac. The machine/computer only needs a software called PVM. For example, if we executed Python program on Windows operating system and got the Byte code, and later we want to run it on Linux OS then we can simply run that byte code on Linux, later we can also run it on Mac OS. We just need Interpreter(PVM) installed along with these operating systems and we are good to go.

5.   Procedural and object oriented language

Yes, object oriented feature must be available in a programming language to implement real world problems. Everything is an object in Python. We will discuss about object oriented features in book “Python Volume 2”. I wrote this feature here for the sake of completeness. Python is both a procedural and an object oriented programming language. C is a procedural language (where we write functions only), C++ and Java are object oriented languages (where we create classes and objects). So we can write programs in Python without creating a single Class like C and we can also write programs using Class and objects like C++ and Java.

6.   Portable

Python is a portable language. When a program yields the same result on any computer in the world, no matter if it is running on Windows, Linux, Mac or any other operating system or hardware, then it is called a portable program. People get confused with Portability and machine dependency because somewhere they seem identical but they are not. Keep in mind that, portability means producing the same output on any machine and machine independency means ability to running the same code on any machine.

7.   Very short programs

Python programs are very short (approximate 2 to 10 times) as compared to other programming languages like C and Java. We can write programs in very less lines/statements since we do not need to declare anything, we need not create any Class unlike Java, we need not create any function unlike C. In C we have to create main() function, in Java we have to create a Class but in Python we can directly write executable statements. Look at the following codes –

 

C code –

 

#include<stdio.h>

#include<conio.h>

void main()

{

clrscr();

printf(“a program”);

getch();

}

 

Java code –

 

class Sample

{

public static void main(String args[])

{

System.out.println(“a program”);

}

}

 

Now observe the Python code –

 

Python code

 

>>> print(“a program”)

 

Did you see the difference? Where C and Java codes are at least 7 to 8 lines, a Python code can be written in just one line.

Comments

Popular posts from this blog

Python 4.4 - Points to remember

Python 3.6 - Points to remember

Python 3.3 - Datatypes in Python