1. What is Python?
Features of Python
What we can do with Python?
Companies using python today
Installing Python
Python as a Calculator/Arithmetic Expression
2. Python is a VHLL (Very High Level Language).
VHLL is designed to reduce the complexity
and to reduce amount of source code
required to create a program
Created by Guido van Rossum (Univ. of
Amesterdam) in 1991.
3. ▪ What is a high-level programming language?
– Not interpretable or directly executable by the CPU
– Has to be translated into a low-level language (assembly
language) or the executable machine language
– E.g.: Python (C, C++, Java, Ruby, …)
▪ Advantages (as compared to low-level languages):
– Easier to implement and require shorter amount of time to
write
▪ (Very) English like
▪ More readable/comprehensible by programmers
– Portable and platform independent
▪ Programs just have to be written once but can be
run on any types of computer platform (without
much modification effort)
4. ▪ When you execute a Python program:
– Source code of your program (.py files) is compiled
(translated) into a format known as byte code
▪ Byte code is a lower-level, platform-independent
representation of the source code of your program
▪ Byte code of your programs are stored as .pyc files
in the subdirectory named pycache.
▪ Once a program has been compiled into byte code
(and whenever the byte code is loaded from the
.pyc file):
– Each of the byte code instructions will be interpreted and
executed by the runtime execution engine, Python Virtual
Machine (PVM)
6. Python is an interpreted, interactive, object-oriented
programming language.
Python is supported with a rich collection of
libraries or packages (i.e. ready-to-use code) to
build sophisticated programs.
Python combines remarkable power with very clear
syntax.
It has modules & very high level dynamic data type.
7. System Programming
Graphical User Interface Programming
Database Programming
Internet Scripting
Gaming, Images, Robot etc.
Data Analytics
9. Available freely for most operating system on:
https://www.python.org/
Available currently in two versions:
Python 2.x & Python 3.x
What are the differences:
Python 2.x is the status quo
Python 3.x is the present and the future of
the language
Which version should I use:
i) If you are working on a new, fully independent
project, you can use 3.x
ii)If your work has dependencies it is safer to use
2.x...
10. IDLE is a simple Python integrated
development environment available for
Windows, Linux, and Mac OS X.
IDLE has a built in editor.
You may type the above one line Python
program directly into IDLE and press enter to
execute the program.
11.
12. Python can be used as a simple calculator:
>>> 2+1
>>> 3
>>> 4-1
>>> 3
>>> 2*2
4
>>> 12/3
4
13. >>> n = 1
>>> z = 2*n
>>> z
>> >2
OR
>>> print (z)
2
OR
>>> print(“Value of z=“,z)
>>> Value of z=2
14. The available arithmetic operators are:
Operator Stands for Precedence
+ sum 0
- subtraction 0
* multiplication 1
/ division 1
// integer division 1
% remainder 1
** power 2
16. Python has a limited knowledge of mathematical
functions.
There is however a module, math, that extends
that: sqrt, factorial, pow, etc...
For example:
>>> import math
>>> math.sqrt(25))
5
OR
>>> from math import sqrt
>>> sqrt(25)
5
17. Python also handles complex numbers:
Imaginary numbers are written with the suffix j or J.
Complex number have the form (real+imag j) or
with complex(real,imag)
18. Complex number have the form (real+imag j)
A complex number z has a real part and an
imaginary part, which are accessible with
z.real and z.imag.
>>> z = 3.0+4.0j
>>> z.real
3.0
>>> z.imag
4.0
19. Structure of a Python program:
Programs are composed of modules.
Modules contain statements(instructions) and
expressions.
Instructions and expressions create and
process objects.
20. Objects correspond to a certain memory
region to which a unique memory address is
associated and in which we store:
Data,
Information about the data,
Functions that act upon the data.
21. For example:
>>> x = 123
creates the object 123, somewhere in
memory and gives it the name x.
We can also say that x “is reference to” the
object or even that “it points to” the object.
22. We can easily obtain the type and unique memory
address for an object:
>>> x = 1.2
>>> print(x)
1.2
>>> type(x)
<type float>
>>> id(x)
135625436
23. It is possible to give more than one name to
an object. This is called aliasing:
>>> x = 45
>>> y = 45
>>> id(x)
135363888
>>> id(y)
135363888
24. We can even do aliasing in just one go:
>>> x = y = 45
>>> id(x)
135363888
>>> id(y)
135363888