0% found this document useful (0 votes)
3 views18 pages

Class-1-Introduction - Python

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1/ 18

Introduction to Python

Topics to be covered
• Why python is popular
• Brief history of python
• Features of Python
• Comparison of python with C and Java
• Execution of a python program
• Installing python for windows
Why python is popular
Procedure Oriented Programming languages
Collection of functions
Ex: C,FORTRON,PASCAL
written using functions, Hence in C all
statements must be written in main function
Object Oriented Programming languages
to solve real life problems
Ex. JAVA,.NET uses concepts of classes and objects
Contd.
• Java is the most popular language. Draw back
is everything is represented in terms of classes
and objects
Exercise: Write a java program to add two
numbers
Write a C program to add two number
Observation: Length of C program is less but real
life problems can not be solved
• A language which includes C and Java style
coding is required.
• Python is the language which contains the
features of C and Java
#python program to add two numbers
a=b=10
print(“sum=“,a+b)
Brief History
• Guido Van Rossum developed a language to fill
the gap between C and Shell in the year 1991
at the centre for mathematics and computer
science managed by dutuch Government. This
has lead to the development of python.
• Python name is selected TV show Monty
pythons Flying circus.
• First version released on feb 20 1991
• Logo of python inter winded snakes
Features of Python
• Simple
• Easy to learn
• Open source
• High Level language
• Dynamically typed
• platform independent
• portable
• Procedure and object oriented
Contd.

• Simple: simple bcz uses English like statements


• Easy to learn: Uses few keywords and has
simple syntax and structure. C language
constructs hence it is migration from C to
python
• Open Source: Freely available software. Hence
downloaded from www.python.org website
Contd.
• High level language: easy to learn and
understand
• Dynamically typed: Need not to declare
anything. Assignment statement binds name
to object
• Platform Independent: Compiler generates
byte code(fixed set of instructions) which runs
on any OS using PVM. Hence python ideal for
any network or internet
Contd.
• Portable: Program gives same result on any
computer then it is called portable program
• Procedure and Object Oriented: It supports
both C and Java constructs
Comparison of python with C

C PYTHON
C is procedure oriented language Python is object-oriented language
C program executes much faster Python program executes much slower
It is compulsory to declare varibles,arrays
It is not compulsory
etc
Python language type discipline is
C language type discipline is static and
dynamic and strong
weak

Pointer concept is used in C Python does not support pointer concept


Switch statement supported in C Switch statement not supported in C
C supports three loop statements for,
Python supports only for and while
while and do..while
In C the variable in for loop is not
incremented automatically In Python the variable in for loop
for(i=1;i<=10;i++) increments automatically
{ for i in range(10):
printf(“%d\n”,i) print(i)
}
Contd..
C PYTHON
C does not have exception handling Python handles exceptions and hence
facility hence C programs are weak python program are robust
Memory allocation are done using calloc()
Memory allocation and deallocation is
and malloc() and deallocation is done
done automatically by PVM
using realloc() or free function
Automatic garbage collector is available in
C does not support garbage collector
python
Python supports only single dimensional
C supports single and multi dimensional
array. To use multi- dimensional array we
arrays
should use third party application numpy
The array index should be positive or
negative integer. Negative index
The array index should be positive integer represents locations from the end of the
int a[4]: array
a[4]={10,20,30,40}; a=[10,20,30,40]
for(i=0; i<4;i++) for i in range(4):
printf(“%d\n”,a[i]) print(a[i])
for i in range(-1,-5,-1):
print(a[i])
Contd..
C PYTHON
Checking the location outside the It is supported in Python
allocation of the array is not supported in
C
Indentation of statement is not necessary Indentation of statement is compulsory
in C because it represents a block of
statements
Semicolon is used to terminate the New line indicates the end of the
statement and comma is used to separate statements and semicolon is used as
the expression expression separators
Supports in-line assignment Python does not support in line
int a=10,b=10; assignment
a=10
a=int(10)
Comparison of python with Java
JAVA PYTHON
Java is true object oriented It is combination of procedure and object
oriented
Java programs are lengthier one contains Python programs are compact and are
more lines written using very less number of lines
Type discipline is static Type discipline is dynamic
It is compulsory to declare variables, Type declaration is not required in python
arrays etc
Java supports three loop statements for, Python supports while and for loops
while and do..while
Java has switch statement Python does not have switch statement
The variable in for loop does not The variable in the for loop increments
increments automatically. But in for each automatically
loop it will increment automatically
Contd..
JAVA PYTHON
Memory allocation and deallocation is Memory allocation and deallocation is
done automatically by JVM done automatically by PVM
Java supports single and multi Python supports only single dimensional
dimensional arrays arrays. To works with multi dimensional
array we should use third party
application like numpy
The array index should be positive The array index can be positive or
number negative integer number. Negative index
represents locations from the end of the
array
Checking the location outside the It is supported in Python
allocation of the array is not supported in
C
Contd..
JAVA PYTHON
Indentation of statement is not necessary Indentation of statement is compulsory
in Java because it represents a block of
statements
Semicolon is used to terminate the New line indicates the end of the
statement and comma is used to separate statements and semicolon is used as
the expression expression separators
In java the collection objects like Python collection objects like lists and
Stack,LinkedLists or Vector store only dictionaries can store objects of any type
objects but not primitive data types like including numbers
integer numbers
Execution of Python Program
PYTHON
PYTHON
COMPILED 1010100001
PROGRAM OUTPUT
FILE 00001111
X.py
X.pyc
Machine code
Computer

Compile
Run Using Python
Using
Virtual Machine
Python
Compiler
• https://anaconda.org/anaconda/python
• Python anaconda cloud
• Download

You might also like