Download as pdf or txt
Download as pdf or txt
You are on page 1of 23

ESSENTIALS OF PYTHON PROGRAMMING

INSTALLATION AND SETUP


Content of this lecture
• Python Introduction
• Installation & Environment Setup

3
Introduction
• Python was developed by Guido Van Rossum during 1985- 1990.
• It is named after a TV Show called ‘Monty Python’s Flying Circus’ and
not after Python-the snake.
• It is an open source, platform independent, general-purpose high-level
programming language which contains features of functional
programming language like C and object-oriented programming
language like java.
• Python is case sensitive in nature.

4
Python Version
• Python programming language is being updated regularly with new
features and supports.
• There are lots of update in Python versions, started from 1994 to
current release.

5
Python Version
Python Version Released Date

Python 1.0 January 1994


Python 1.5 December 31, 1997
Python 1.6 September 5, 2000
Python 2.0 October 16, 2000
Python 2.1 April 17, 2001
Python 2.2 December 21, 2001
Python 2.3 July 29, 2003
Python 2.4 November 30, 2004
Python 2.5 September 19, 2006
Python 2.6 October 1, 2008
Python 2.7 July 3, 2010
Python 3.0 December 3, 2008
Python 3.1 June 27, 2009
Python 3.2 February 20, 2011
Python 3.3 September 29, 2012
Python 3.4 March 16, 2014
Python 3.5 September 13, 2015
Python 3.6 December 23, 2016
Python 3.7 June 27, 2018
Python 3.8 October 14, 2019 6
Python Installation
• Latest version of python is 3.12.2
• We can freely download it from https://www.python.org/downloads/
• During installation use the custom installation option and Install the
python in any location of your choice. e.g. d:\python.
• Check the option to set the python path.

7
Python Path Setting Manually
• To set the path of the python directory manually in the OS environment
variables, do the following:
• My computer icon properties Advanced system settings Environment
variables  system variables  Path  Edit will display the directories
involved in the path.
• At the end of that path, add the directory where python is installed in the system
with a dot symbol at the end.

8
Python Installation
• If path is not known then run the following code in python IDLE:
import sys
for p in sys.path:
print(p)

9
Python Installation
• Outcome will be following:
• D:\Python\Lib\idlelib
• D:\Python\python37.zip
• D:\Python\DLLs
• D:\Python\lib
• D:\Python
• D:\Python\lib\site-packages

10
Running a python program
• There are 3 ways of executing a python program.
• Using python’s command line window
• Using python’s IDLE graphic window/python shell
• Directly from command prompt of operating system
• Write the python program using any editor and save it in desired
directory.
• To get help on any topic write help() on python command line window
and press enter. Now type modules/topics and press enter. This will
display the list of modules/topics available in python.

11
Running a python program from python shell
• Open the IDLE/python shell window
• To create a new file, press Alt+N and give the name and specify the
location for new file.
• To open an existing file, FileOpen specify the path
• Once file has been opened or code in new file has been written, press
F5 key.
• This will display the result on python shell

12
Running a python program from command prompt
of Operating System
• Using any editor, type the python program and save it in a directory.
• Now through the command prompt, go to the directory where program
has been saved.
• Call the program name with.py extension
program_name.py
• Now press enter and see the result of the program.

13
Python Program Execution
• A python program is always saved with .py extension.

• Byte code represents the fixed set of instructions that represents all
operations like arithmetic, comparison, memory related operations etc.
• Byte code can run on any OS and hardware so it is system and platform
independent.

14
Python Program Execution
• Size of each byte code instruction is 1 byte, so it is called byte code.
• PVM uses an interpreter which understands the byte code and converts
it into machine code understandable to that processor and into the
format understandable to OS.
• Machine code instructions are then executed by processor and results
are displayed.

15
Python Compiler
• Cpython: This is written in C language. Python program is internally
converted into byte code using C language functions and byte code is
run on interpreter available in PVM created in C language.
• Jython: This is written in java language. Jython compiler first compile the
python program into java byte code and it is executed by java virtual
machine (JVM) to produce the output.

21
Python Compiler
• IronPython: This is written in C# language. Python program after
compilation gives an intermediate language (IL) which runs on common
language runtime (CLR) to produce the output.
• Pypy: This is written in python language.

22
Memory Management in Python
• In python, memory allocation and deallocation are done automatically
at runtime.
• Memory manager is a module inside PVM which allocates memory to all
objects.
• Everything is considered as object in python. E.g. strings, list, number
are all objects. All objects are stored on separate memory heap at run
time. Size of heap memory depends upon size of computer RAM.
• Garbage collector is another module in PVM which will deallocate
memory for the unused objects. This module is executed automatically
when the Python program is running in memory.
23
C vs Python
C is structure programming language. Python blends the functional programming
with object oriented programming features.
C program executes faster. Python program executes slower relative to
C.
It is compulsory to declare the datatype Type declaration is not required.
of variable.
Pointer concept is used in C. Pointer concept is not available in python.
Does not have exception handling It has exception handling feature.
feature.
C has switch statement. Python does not have switch statement.
C has for, while and do while loop. Python has for and while loop.
24
C vs Python
Variable in loop does not increment Variable in loop increments
automatically. automatically.
There is no garbage collector. Automatic garbage collector is available
in Python.
Array index must be positive integer. Array index can be positive or negative
integer
Indentation is not necessary Indentation is necessary to represent
the block
Semicolon is used to terminate the New line indicates the end of statement
statement

25
Java vs Python
Java is object oriented programming Python blends the functional programming
language. with object oriented programming features.
It is compulsory to declare the datatype Type declaration is not required.
of variable.
Java has switch statement. Python does not have switch statement.
Java has for, while and do while loop. Python has for and while loop.
Variable in loop does not increment Variable in loop increments automatically.
automatically.
Memory allocation and deallocation is Memory allocation and deallocation is done
done automatically by JVM. automatically by PVM.

26
Java vs Python
Java support single and multi dimensional Python supports only single dimensional
array. array.
Array index must be positive integer. Array index can be positive or negative
integer.
Indentation is not necessary. Indentation is necessary to represent the
block.
Semicolon is used to terminate the New line indicates the end of statement.
statement.

27

You might also like