Introduction
Python
Python
● Combines the features of C and JAVA
● It offers elegant style of developing programs like C
● It offers classes and objects like Java
Features of Python
● Simple
● More clarity
● Less stress on reading and understanding the syntax
● Easy to learn
● Uses very few keywords
● Very simple structure, resembles C
● Open source
● High level language
● Dynamically typed
● Type of the variable is not declared statically
Features of Python...
● Platform Independent
○ Python compiler generates byte code
○ PVM interprets the byte code
● Portable
● Procedure and Object oriented language
● Interpreted
● Extensible
● Embeddable
● Huge Library
● Scripting Language
● Database Connectivity
○ Provides interfaces to DB like Oracle, Sybase or MySql
Execution of a Python Program
● Example:
● x.py → python_compiler → x.pyc → PVM → Machine_Code
● python -m py_compile x.py
● python x.cpython-34.py
● python -m dis add.py
Memory Management in Python
● In C or C++, allocation and deallocation of memory will be done manually
● malloc(), calloc(), realloc() or free()
● In python, it is done at run time automatically
● Memory Manager inside the PVM takes care of allocating memory for all objects in
Python.
● All objects are stored in Heap
Garbage Collection in Python
● Garbage collector is a module in Python that is useful to delete objects from memory
which are not used in the program.
● The module that represents the GC is gc.
● It will keep track of how many times the object is referenced.
● If it is referenced 0 times, then gc will remove object from memory.
C Vs Python
C Python
Procedure Oriented language Object Oriented language
Faster Slower
Compulsory to declare the data types of variables Data Types are not required
Type discipline is static and weak Dynamic and strong
Pointers concept present No pointers concept
No exception handling facility Exception handling facility is robust
Do-while is present Absent
Has switch statement No Switch
C Vs Python
C Python
Manually allocate the memory Automatic
Absence of GC GC is present
Supports Single and multi dimensional arrays Supports only single dimension
Array should be positive Can be Positive or negative
Array bounds checking is not present Present
Indentation is not necessary Strictly needed
Every statement is terminated by ; No semicolon

Introduction to Python

  • 1.
  • 2.
    Python ● Combines thefeatures of C and JAVA ● It offers elegant style of developing programs like C ● It offers classes and objects like Java
  • 3.
    Features of Python ●Simple ● More clarity ● Less stress on reading and understanding the syntax ● Easy to learn ● Uses very few keywords ● Very simple structure, resembles C ● Open source ● High level language ● Dynamically typed ● Type of the variable is not declared statically
  • 4.
    Features of Python... ●Platform Independent ○ Python compiler generates byte code ○ PVM interprets the byte code ● Portable ● Procedure and Object oriented language ● Interpreted ● Extensible ● Embeddable ● Huge Library ● Scripting Language ● Database Connectivity ○ Provides interfaces to DB like Oracle, Sybase or MySql
  • 5.
    Execution of aPython Program ● Example: ● x.py → python_compiler → x.pyc → PVM → Machine_Code ● python -m py_compile x.py ● python x.cpython-34.py ● python -m dis add.py
  • 6.
    Memory Management inPython ● In C or C++, allocation and deallocation of memory will be done manually ● malloc(), calloc(), realloc() or free() ● In python, it is done at run time automatically ● Memory Manager inside the PVM takes care of allocating memory for all objects in Python. ● All objects are stored in Heap
  • 7.
    Garbage Collection inPython ● Garbage collector is a module in Python that is useful to delete objects from memory which are not used in the program. ● The module that represents the GC is gc. ● It will keep track of how many times the object is referenced. ● If it is referenced 0 times, then gc will remove object from memory.
  • 8.
    C Vs Python CPython Procedure Oriented language Object Oriented language Faster Slower Compulsory to declare the data types of variables Data Types are not required Type discipline is static and weak Dynamic and strong Pointers concept present No pointers concept No exception handling facility Exception handling facility is robust Do-while is present Absent Has switch statement No Switch
  • 9.
    C Vs Python CPython Manually allocate the memory Automatic Absence of GC GC is present Supports Single and multi dimensional arrays Supports only single dimension Array should be positive Can be Positive or negative Array bounds checking is not present Present Indentation is not necessary Strictly needed Every statement is terminated by ; No semicolon