KEMBAR78
Python ppt | PPT
1
PRESENTATION ON PYTHON
By Rohit Kumar Verma
B. Tech (CSE)
2
Intorduction
 Python is a general purpose high level programming language.
 Python was developed by Guido Van Rossam in 1989 while working at
National Research Institute at Netherlands.
 But officially Python was made available to public in 1991. The official Date
of Birth for Python is : Feb 20th 1991.
 Python is recommended as first programming language for beginners.
 It is interpreted , object oriented and procudural language
 Python language is being used by almost all tech-giant companies like –
Google, Amazon, Facebook, Instagram, Dropbox, Uber… etc.
 There are two major Python versions- Python 2 and Python 3. Both are quite
different.
3
Program to add two no.
Java program
public class Add{
pulic static void main(String []args){
Int a,b;
a=10;
b=20;
System.out.println(“Addition is =”+(a+b))
}
}
C-Program
void main()
{
int a,b;
a =10;
b=20;
printf("The Sum:%d",(a+b));
}
Python program
a,b=10,20
print(“the sum is =”,(a+b))
4
Guido developed Python language by taking almost all programming features from
different languages
1. Functional Programming Features from C .
2. Object Oriented Programming Features from C++ .
3. Scripting Language Features from Perl and Shell Script .
4. Modular Programming Features from Modula-3 .
5. Most of syntax in Python Derived from C and ABC languages.
5
Where we can use python
We can use everywhere. The most common important application areas are
1) For developing Desktop Applications
2) For developing web Applications
3) For developing database Applications
4) For Network Programming
5) For developing games
6) For Data Analysis Applications
7) For Machine Learning
8) For developing Artificial Intelligence Applications
9) For IoT
6
Features of Python
 Simple and easy to learn
 Open source
 High level Programming language
 Platform Independent
 Portability
 Dynamically Typed
 Both Procedural Oriented and Object Oriented
 Interpreted
 Extensible
 Embedded
 Extensive Library
7
Python version
 Python 1.0V introduced in Jan 1994
 Python 2.0V introduced in October 2000
 Python 3.0V introduced in December 2008
 Current version of python 3.8.0, documentation released on 14
October 2019.
Note: Python 3 won't provide backward compatibility to Python2 i.e
there is no guarantee that Python2 programs will run in Python3.
8
Reserved Words in Python
 In Python some words are reserved to represent some meaning or functionality.
Such types of words are called reserved words.
 There are 33 reserved words available in Python.
True, False, None
and, or ,not,is
if, elif, else
while, for, break, continue, return, in, yield
try, except, finally, raise, assert
import, from, as, class, def, pass, global, nonlocal, lambda, del, with
Note:
1. All Reserved words in Python contain only alphabet symbols.
2. Except the following 3 reserved words, all contain only lower case alphabet symbols
True,False,None
9
Data Type in Python
 Data type represent the type of data present inside a variable
 In python , Based on value provided , the type will be automatically assigned .
Python contain following inbuilt datatype
Int Float Complex Bool
Str Bytes Bytearray Range
List Tuple Set Frozenset
Dict None
10
Operators in python
 Arithmetic Operator ( + , - , / , * , % , // , ** )
 Relational Operator ( > , < , <= , >= )
 Equality operator( == , != )
 Logical Operator( and , or , not )
 Bitwise Operator ( & , | , ^ , ~ , << , >> )
 Assignment Operator ( += , -= , /= , *= , %= , //= , **= ,&= , |= , ^= , << =, >>=)
 Special operator and member operator(is ,in)
Operator chaining
10<20<30<40 True 10<20<60<50 False
possible in relational operator and equality operator (==)
11
Decorator
Decorator is a fuction which take fuction as argument and extends its functionality and return modified function
def hello_decorator(func):
def inner1():
print("Hello, this is before function execution")
func()
print("This is after function execution")
return inner1
@hello_decorator or function_to_be_used = hello_decorator(function_to_be_used)
def function_to_be_used():
print("This is inside the function !!")
function_to_be_used()
Output:
Hello, this is before function execution
This is inside the function !!
This is after function execution
12
Generator
 A Function which is used to generate sequence of values .
 It is similar to ordinary function
 It uses yield keyword to return sequence values
def simpleGeneratorFun():
yield 1
yield 2
yield 3
for value in simpleGeneratorFun():
print(value)
Output :-
1
2
3
13
Zipping and Unzipping files
 To perform zipping operation
create zip file class object with name of zip file
f = ZipFile(“files.zip”,”w”,”ZIP_DEFLATED”)
Now, we can add files by using write() method
f.write(filename)
 To perform unzip operation
f=ZipFile(“files.zip”,” r ”, ZIP_STORED )
now , we can get all files names present in that zip file by using namelist() method
names = f.namelist()
14
Working With Dorectories
 python provides inbuilt module os , which contain several function to perform directories related operation
 To know current working directory
cwd = os.getcwd()
 To created sub directory in the current working directory
os.mkdir(“dirName”)
 To create multiple subdirectories like sub1 in that sub2 in that sub3
os.makedirs(“sub1/sub2/sub3”)
 To remove directoriy
os.rmdir(“name”)
 To rename the directory
os.rename(“mysub”,”newdir”)
15
__name__ , __init__
__name__
 Since there is no main() function in Python, when the command to run a python program
is given to the interpreter, the code that is at level 0 indentation is to be executed.
__name__ special variable and it has two values
1. __main__ ( if program is executed as indivisual program )
2.module’s name (it the program is executed as module from another program)
__init__
 if a folder or directory contain __init__.py file , is considered as a python package.
 __init__ is used for constructor of a class
16
Python Limitations
 Performance and Speed
 Incompatibility of Two Versions
 Requires Additional Testing
 Not use for mobile applications

Python ppt

  • 1.
    1 PRESENTATION ON PYTHON ByRohit Kumar Verma B. Tech (CSE)
  • 2.
    2 Intorduction  Python isa general purpose high level programming language.  Python was developed by Guido Van Rossam in 1989 while working at National Research Institute at Netherlands.  But officially Python was made available to public in 1991. The official Date of Birth for Python is : Feb 20th 1991.  Python is recommended as first programming language for beginners.  It is interpreted , object oriented and procudural language  Python language is being used by almost all tech-giant companies like – Google, Amazon, Facebook, Instagram, Dropbox, Uber… etc.  There are two major Python versions- Python 2 and Python 3. Both are quite different.
  • 3.
    3 Program to addtwo no. Java program public class Add{ pulic static void main(String []args){ Int a,b; a=10; b=20; System.out.println(“Addition is =”+(a+b)) } } C-Program void main() { int a,b; a =10; b=20; printf("The Sum:%d",(a+b)); } Python program a,b=10,20 print(“the sum is =”,(a+b))
  • 4.
    4 Guido developed Pythonlanguage by taking almost all programming features from different languages 1. Functional Programming Features from C . 2. Object Oriented Programming Features from C++ . 3. Scripting Language Features from Perl and Shell Script . 4. Modular Programming Features from Modula-3 . 5. Most of syntax in Python Derived from C and ABC languages.
  • 5.
    5 Where we canuse python We can use everywhere. The most common important application areas are 1) For developing Desktop Applications 2) For developing web Applications 3) For developing database Applications 4) For Network Programming 5) For developing games 6) For Data Analysis Applications 7) For Machine Learning 8) For developing Artificial Intelligence Applications 9) For IoT
  • 6.
    6 Features of Python Simple and easy to learn  Open source  High level Programming language  Platform Independent  Portability  Dynamically Typed  Both Procedural Oriented and Object Oriented  Interpreted  Extensible  Embedded  Extensive Library
  • 7.
    7 Python version  Python1.0V introduced in Jan 1994  Python 2.0V introduced in October 2000  Python 3.0V introduced in December 2008  Current version of python 3.8.0, documentation released on 14 October 2019. Note: Python 3 won't provide backward compatibility to Python2 i.e there is no guarantee that Python2 programs will run in Python3.
  • 8.
    8 Reserved Words inPython  In Python some words are reserved to represent some meaning or functionality. Such types of words are called reserved words.  There are 33 reserved words available in Python. True, False, None and, or ,not,is if, elif, else while, for, break, continue, return, in, yield try, except, finally, raise, assert import, from, as, class, def, pass, global, nonlocal, lambda, del, with Note: 1. All Reserved words in Python contain only alphabet symbols. 2. Except the following 3 reserved words, all contain only lower case alphabet symbols True,False,None
  • 9.
    9 Data Type inPython  Data type represent the type of data present inside a variable  In python , Based on value provided , the type will be automatically assigned . Python contain following inbuilt datatype Int Float Complex Bool Str Bytes Bytearray Range List Tuple Set Frozenset Dict None
  • 10.
    10 Operators in python Arithmetic Operator ( + , - , / , * , % , // , ** )  Relational Operator ( > , < , <= , >= )  Equality operator( == , != )  Logical Operator( and , or , not )  Bitwise Operator ( & , | , ^ , ~ , << , >> )  Assignment Operator ( += , -= , /= , *= , %= , //= , **= ,&= , |= , ^= , << =, >>=)  Special operator and member operator(is ,in) Operator chaining 10<20<30<40 True 10<20<60<50 False possible in relational operator and equality operator (==)
  • 11.
    11 Decorator Decorator is afuction which take fuction as argument and extends its functionality and return modified function def hello_decorator(func): def inner1(): print("Hello, this is before function execution") func() print("This is after function execution") return inner1 @hello_decorator or function_to_be_used = hello_decorator(function_to_be_used) def function_to_be_used(): print("This is inside the function !!") function_to_be_used() Output: Hello, this is before function execution This is inside the function !! This is after function execution
  • 12.
    12 Generator  A Functionwhich is used to generate sequence of values .  It is similar to ordinary function  It uses yield keyword to return sequence values def simpleGeneratorFun(): yield 1 yield 2 yield 3 for value in simpleGeneratorFun(): print(value) Output :- 1 2 3
  • 13.
    13 Zipping and Unzippingfiles  To perform zipping operation create zip file class object with name of zip file f = ZipFile(“files.zip”,”w”,”ZIP_DEFLATED”) Now, we can add files by using write() method f.write(filename)  To perform unzip operation f=ZipFile(“files.zip”,” r ”, ZIP_STORED ) now , we can get all files names present in that zip file by using namelist() method names = f.namelist()
  • 14.
    14 Working With Dorectories python provides inbuilt module os , which contain several function to perform directories related operation  To know current working directory cwd = os.getcwd()  To created sub directory in the current working directory os.mkdir(“dirName”)  To create multiple subdirectories like sub1 in that sub2 in that sub3 os.makedirs(“sub1/sub2/sub3”)  To remove directoriy os.rmdir(“name”)  To rename the directory os.rename(“mysub”,”newdir”)
  • 15.
    15 __name__ , __init__ __name__ Since there is no main() function in Python, when the command to run a python program is given to the interpreter, the code that is at level 0 indentation is to be executed. __name__ special variable and it has two values 1. __main__ ( if program is executed as indivisual program ) 2.module’s name (it the program is executed as module from another program) __init__  if a folder or directory contain __init__.py file , is considered as a python package.  __init__ is used for constructor of a class
  • 16.
    16 Python Limitations  Performanceand Speed  Incompatibility of Two Versions  Requires Additional Testing  Not use for mobile applications