What is Python (Programming Language)?
Salient Features:
- SIMPLE AS BASIC: Python is a sort of modern day BASIC language.
- BEGINNER TO ADVANCED: It is right for beginners and it is truly all purpose in modern times. Language for console applications, GUI applications, scientific applications and web applications.
- INTERPRETED: It is an interpreted language. This means that line by line error checking is done.
- READABLE: It is highly readable without too scary curly braces.
- INDENTED BLOCKS: Code construct is simple and neatly indented with tabs or fixed number of spaces to define blocks within code.
- DYNAMIC DATA TYPES: Data typing is automatic and it does not need declarations. This also called dynamic typing concept in python. (for e.g. a=3 and not int a=3)
- IN-BUILT DAY-TO-DAY TASKS: Powerful set of features are available to perform most day to day tasks. (For e.g. an array a=[1,2,3] can be reversed by simply writing a.reverse() )
- EXTENSIBLE STANDARD AND USER DEFINED LIBRARIES: Easily extensible by using standard libraries or user defined libraries for things like GUI, web frameworks, multimedia, database interaction, networking, image processing, scientific computing, documentation etc.
- MANAGED MEMORY: Python performs excellent memory management, without passing the botheration to the user.
- SMALL AND EFFICIENT: Python code is usually small and efficient as compared to
many other high level languages for many simple and complex tasks.
- OOPS SUPPORT: Python supports object oriented as well as procedural programming.
- PORTABLE: Python code is easily portable and runs without modifications on most computing platforms.
Genesis of Python:
- Conceptulised by Dutch programmer Guido Von Rossum in late 1980s.
- Version 2.X series existed since year 2000.
- Version 3.x series cam in 2008
Demonstration examples:
Example 1:
a=2 # no type for a
b=3 # no line terminator required
print(a+b) #direct use of operator
This will output
5
Example 2:
#watch indented blocks of function and for loop
#watch a simple array declaration termed list
def test():
a=[1,2,3]
for x in a:
print x
This will output
1
2
3
Example 3:
a=[1,2,3] #List is like an array
a[0]=5 #List item can be modified
print a[0]
b=(1,2,3) #Tuple - observe use of round brackets
# b[0]=5 #This statement is not allowed. Tuple items can not be modified
print b[0]
c={"A":4,"B":5} #Dictionary contains key value pairs - observe curly braces
print(c["A"])
c["A"]=6 #Dictionary items can be modified
print(c["A"])
This will output
5
1
4
6
Notes:
- # is used for commenting
- single quote ‘ ‘ and double quote ” “ are for same purpose, for marking string literal.
- : is required for special lines which are expecting more following instruction, for e.g. test, for, while etc.
- print can be used directly as print x in version 2.X series but version 3.X series requires print(x)