Features of Python

Let us take a closer look at some of the salient features of Python.


1. Enhanced Readability

In Python, uniform indents are used to delimit blocks of statements instead of curly brackets like in C, C++ and Java. This enhances readability.

In  C, C++, Java

if (X%2==0)
{
if (x%3==0)
   System.out.println("divisible by 2 and 3");
else
   System.out.println("divisible by 2 not divisible by 3");
}
else
{
if (x%3==0)
   System.out.println("divisible by 3 not divisible by 2");
else
   System.out.println("not divisible by 3 nor by 2");
}

In Python

if num%2 == 0:
   if num%3 == 0:
       print ("Divisible by 3 and 2")
   else:
       print ("Divisible by 2 not divisible by 3")
else:
   if num%3 == 0:
       print ("Divisible by 3 not divisible by 2")
   else:
       print ("Not divisible by 3 nor by 2")


2. Dynamic Typing

In Python, a variable to be used in a program need not have prior declaration of its name and type. You will learn details about variables in the next module.

Java is statically typed

String var;  // Variable is explicitly declared.
var=”Hello”;
var=1234; // Not allowed because the variable has been declared as a String.

Python is dynamically typed

var=”Hello” # Variable is NOT explicitly declared.
var=1234 # Allowed although variable was initially String type.


3. Interpreted Language

Python is an interpreter-based language. An interpreter executes one instruction at a time. So if there is an error on line 7 of the code, it will execute instructions till line 6 and then stop. This is unlike a compiler which will not execute any of the instructions even if there is a single error. Thus, an interpreter is useful if you are new to programming because it allows you to see partial output of your code and identify the error location more easily.


Java program  (Compiled)

//This program will not display any of the phrases as there is an error on line 7.

1 public class test
2 {
3   public static void main(String args[])
4   {
5     System.out.println("Welcome to");
6     System.out.println("Python training program");
7     System.out.println(From Internshala);
8   }
9 }

Python program (Interpreted)

#This program will display two phrases but not the third phrase as there is an error in line 3.

print ("welcome to")
print ("Python training program from")
print (Internshala)


4. Extensible Language

Python extension modules implement new built-in object types and can call C libraries and system calls which Python doesn’t have direct access to.


5. Standard DB2 API

A standard data connectivity API facilitates using data sources such as Oracle, MySQL and SQLite as a backend to a Python program for storage, retrieval and processing of data.


6. GUI Programming

Standard distribution of Python contains Tkinter GUI kit, which is an implementation of the popular GUI library called Tcl/Tk. An attractive GUI can be constructed using Tkinter. Many other GUI libraries like Qt, GTK, WxWidgets etc. are also ported to Python.


7. Embeddable

Python can be integrated with other popular programming technologies such as C, C++, Java, ActiveX and CORBA.

Comments

Popular posts from this blog

Comparing Python 2.x and Python 3.x

Syntax of Python

IDLE