Python:
--------------------------------------------------------------
---------------------------------
1)why Python?
2)who can learn Python?
3)How Python was Built?
4)Python Real Time Applications
5)Python Usage
6)Python Features
7)Python Comparison with other programming
8)Python Scope and Job market.
9)Python Software Foundation(PSF)
--------------------------------------------------------------
--------------------------------------
Why Python?
Python is a
-General Purpose
-Multi Programming paradigm
-High-level
-interpreted
-user-friendly programming language
Python is a user-friendly programming language which provides
simple syntaxes which looks like normal English stmts.
Python was developed by Guido Van Rossum in the year 1989.
--------------------------------------------------------------
--------------------------------------
Python was built or derived by taking the features or
advantages from various other programming languages
such as
1)Procedural Oriented Programming: ex :C-Language----------
>Functions
2)Object Oriented Programming ex: C++,Java -----------
>Security, Re-usability, flexibility
3)Scripting Languages ex: shell script---------
>dynamic Datatypes
4)Modular Programming ex: modula-3 ----------
>Modules--------->89300
--------------------------------------------------------------
---------------------------------------
Dynamic Datatypes:
C/C++/Java Python
int x=10 x=10 based on the value
assigned the variables are created dynamically
float y=4.5 y=4.5 type(y)----->float
string z="hello" z="hello"
Modules :
python provides modules for each and every domain such as
Data science ------------->separate modules
Machine Learning---------> " "
Big Data-----------------> " "
Testing -----------------> " "
Networking --------------> " "
Animations---------------> " "
OS ----------------------> " "
Oracle-------------------> " "
MySQL--------------------> " "
Excel -------------------> " "
xml ---------------------> " "
csv----------------------> " "
pdf ---------------------> " "
math---------------------> " "
statistics---------------> " "
Administrative Activities> " "
Graphs-------------------> " "
Python Real Time Applications:
Today python is mostly used in developing the following
Applications:
Python Real Time Applications:
1.Web Applications:
2.Automation Applications
-Data science--------->Machine Learning--->
-IOT
3.Bigdata: KB,MB,GB, TB,PB,EB,ZB,YB,SB
4.Scientific Applications:
5 .GUI/Animations :
6. Game Development: PyGame,Pykara ,PySoy
7.Software Development:
8.Bussiness : Tryton
9. Database
10.N/W Programming :Twisted Python
11. Audio and video Applications
12.CAD Applications
13.Embeded Applications
14.Desktop Applications:
15.WebScraping:
16.Computer vision
17.Robotics
18.Data Analysis
Who are using Python Today:
1)Google : Uses Python Script in web Search systems.
2)YouTube : Video sharing service is largely written in
python.
3)MMOG : Massively Multi-player Online Games uses python
4)Maya : A powerful 3D animation system provides python
scripting API
5)iRobot: uses python to develop commercial and military
robotic devices.
6)BitTorrent: File sharing system, began its life as a python
program.
7)Google's App Engine: web development framework uses python
as an application language.
8)IronPort Email server : Uses more than 1 million lines of
python code to do its job.
9)Hardware Testing: Intel, Cisco, HP, Seagate, Qualcomm ,IBM
etc uses python for H/W Testing.
10)Financial Marketing.....
11)Yahoo
12)Instagram
13)Quora
14)Reddit
15)Pinterest
16)Dropbox
Python Features:
1)Powerful standard Library: provides many Built in
Functionalities for performing various operations.
2)Wide varieties of modules :89300 modules
3)Supports interactive mode: User can easily interact with
Python interpreter line by line.
4)Supports dynamic datatypes:
5)supports Object oriented Programming:
6)supports all major databases.
7)Extendable
8)Can be easily integrated with other languages
9)simple and easy and looks like normal English stmts.
Python Comparison with other Programming:
ex: accepting 2 no's from the user and performing addition.
1. Using Java
import java.io.*;
class sample
{
public static void main(String args[]) throws IOException
{
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
System.out.println("Enter 1st No:");
String s1=br.readLine();
int i=Integer.parseInt(s1);
System.out.println("Enter 2nd No:");
String s2=br.readLine();
int j=Integer.parseInt(s2);
System.out.println(i+j);
}
}
2. Using Python:
x=int(input("Enter value of x:"))
y=int(input("Enter value of y:"))
print(x+y)
Python Software Foundation(PSF):
PSF is a non-profit organization devoted to python programming
language.
-It was launched on March 6th,2001.
-Mission : to faster the development of python community.
-in 2005, PSF received "Computerworld Horizon Award" for
cutting-edge Technology
President and Founder : Guido Van Rossum
Headquarters: Delaware, United States
Official website: www.python.org/psf
Python versions:
python 1.xxx ------------>1989
python 2.xxx ------------>2000
python 3.xxx ------------>2008
Latest version of python------------->python 3.10
Stable version of python------------->python 3.7
(mostly used version)
Previous stable version is----------->Python 2.7
Python Installation:
Google-------->python download------------->download----->all
releases----->select python 3.7.4
click 64 bit executable installer---->download starts
double click the downloaded file---------->select add python
to path
go for customize installation------->next----->select location
to install as C:\python39
--- install
check whether python is installed correctly or not:
go to cmdprompt----------->type python------->it should
display python version and interpreter.
Python IDES's:
1)PyCharm---------->mostly used
2)Pydev
3)Komodo
4)Spyder
5)Eclipse
6)NetBeans
7)Jupiter Notebook
8)VSCode
9)Atom
Python Execution Modes: 2 modes of Execution
1)Interactive mode
2)Batch mode
Interactive mode: Here we directly type our python stmts on
interpreter and can easily communicate line by line.
Advantage: For learning Python and to test the functionalities
of python
Batch mode: Here we write set or batch of stmts within
Editors/IDE's and save it by using.py extension and later
submit to python interpreter.
Various Editors:
1)Notepad
2)Edit plus
3)vi
4)nano
5)gedit
Various IDE's (Integrated Development Environment)
1)PyCharm---------->mostly used
2)Pydev
3)Komodo
4)Spyder
5)Eclipse
6)NetBeans
7)Jupyter Notebook
8)VSCode
9)Atom
Developing Python Applications using Editors:
Ex: Notepad
open notepad and type the following python stmts.
x=10
y=20
print(x+y)
print(x-y)
print(x*y)
print(x/y)
save it using sample1.py extension and later submit to python
interpreter.
submitting the file to interpreter------->
go to cmdprompt---->python C:\pythonweekend\sample1.py
It gives the output
here we are writing the code at one place and executing it at
other place instead we can write and execute at a single
place, for that whenever we install python, along with python
we can IDLE(Integrated Development Environment)----->where we
can work with interactive mode as well as
batch mode.
Datatypes: 2 Types
1. Fundamental Datatypes----------->Object holding a single
value.
5 Types
1.int ----->age=25
2.float --->sal=90870.40
3.boolean-->True/False
4.string -->city="Hyderabad"
5.complex-->x+jy
2.Collection Datatypes ----------->Object holding group of
values.
4 Types
1.List ------->[ ] ex: x=[10,20,30,40]
2.Tuple ------->( ) y=(10,20,30,40)
3.Set ------->{ } z={10,20,30,40}
4.Dictionary -->{k:v} p={"Name":"Ajay" ,"Age":25}
k v
Fundamental Datatypes:
i)int
ii)float
iii)Boolean
iv)complex
v)string '''
#working with integers
x=10
y=20
print(x)
print(type(x))
print(id(x))
#Output:
10
<class 'int'>
140725611127880
print(y)
print(type(y))
print(id(y))
#Output
20
<class 'int'>
140725611128200
z=x+y
print(z)
print(type(z))
print(id(z))
#Output:
30
<class 'int'>
140725611128520
# Fundamental Datatypes:
#1.int
#case 1:
x=10
print(x)
print(id(x))
print(type(x))
Output:
10
140725611193416
<class 'int'>
#Case 2: Defining 2 variables with 2 different values--->2
objects are created with 2 different addresses
x=10
y=20
print(x)
print(id(x))
print(type(x))
10
140725611193416
<class 'int'>
print(y)
print(id(y))
print(type(y))
20
140725611193736
<class 'int'>
z=x+y
print(z)
print(id(z))
print(type(z))
30
140725611194056
<class 'int'>
w=y-x
print(w)
print(id(w))
print(type(w))
10
140725611193416
<class 'int'>
# Case 3: defining 2 variables with same values----->only one
object created and its address is returned to both variables
x=10
y=10
print(x)
print(id(x))
print(type(x))
10
140725611193416
<class 'int'>
print(y)
print(id(y))
print(type(y))
10
140725611193416
<class 'int'>
z=x+y
print(z)
print(id(z))
print(type(z))
20
140725611193736
<class 'int'>
#Case 4:initializing multiple values to a variable--->
multiple objects created--->always latest value will be
returned.
x=10
print(id(x))
Output:
140725611193416
x=20
print(x)
print(id(x))
print(type(x))
140725611193736
<class 'int'>
x=10
print(x)
print(id(x))
print(type(x))
140725611193416
<class 'int'>
# Float data type
x=4.5
print(x)
print(type(x))
print(id(x))
4.5
<class 'float'>
1966153698000
y=20
print(y)
print(id(y))
print(type(y))
20
140725611193736
<class 'int'>
z=x+y #int+float------>float
print(z)
print(type(z))
print(id(z))
24.5
<class 'float'>
1966152470512
#String: A String is a sequence collection of Characters
'''
In Python, a string is represented using
1.Single quote(' ')
2.Double quote(" ")
3.Triple quote(''' ''')
Each character of a string is represented or accessed by a
unique index
String supports 2 types of indexes:
1.positive index or Forward index-->starts from left to
right--->index starts with 0
2.Negative index or Backward index-->starts from right to
left-->index starts with -1.
'''
x="python"
print(x)
print(type(x))
print(len(x))
y="programming"
print(x+" "+y) #Concatenation--->adding 2 strings--->1st
string followed by 2nd string
python
<class 'str'>
6
python programming
#String slicing: Extracting particular portion of a string
x="python program"
#Extract---->"python"
print(x[0:6])#Always upper bound is excluded
#Extract--->"prog"
print(x[7:11])
print(x[11:7])#Empty string-->bcoz always slicing in the
forward direction
#Extract--->"prog" using -ve index
print(x[-7:-3])
#Extract-->"program"
print(x[7:14])
print(x[7: ])
print(x[-7: ])
print(x[ :6])
print(x[ : ])
print(x)
print(x[0: ])
print(x[0:14:2]) #(Startvalue,stopvalue,stepvalue)
print(x[::2])
print(x[::-1]) #reverses the string
#Palindrome :If we reverse a string, if we get the same string
then it is a palindrome
#ex:madam,malayalam,dad,mom,nitin
x="madam"
print(x)
y=x[::-1]
print(y)
#String methods:
#1.upper(): To print in uppercase
x="hyderabad"
print(x.upper())
print(x)
#2.lower():To print in lowercase
x="MUMBAI"
print(x.lower())
#3.capitalize():for capitalizing the 1st character of a string
x="india"
print(x.capitalize())
#4.title():for capitalizing the 1st character of each word in
a string
x="good evening hyderabad"
print(x.title())
#ex:
emps="rahul,ajay,blake,miller,james,amar,rohith"
print(emps.title())
#5.replace(): for replacing a portion of a string
x="Java is Easy and Java is simple"
print(x.replace("Java","Python"))
print(x)
#6.Swapcase():for converting one case to another case
x="good evening hyderabad"
print(x.swapcase())
#7.count(): To count the no of occurrences of a sub-string or
a character
x="hello hello hello...how are you???"
print(x.count("hello"))
print(x.count("h"))
#8.format():for substitutions
x="His name is {} and he is a {}"
print(x.format("Ajay","doctor"))
#ex:2
x="{} is the {} of {}"
print(x.format("Delhi","capital","India"))
#9.strip(): For removing the blank spaces before and after the
string
x=" Good Evening Hyderabad "
print(x,len(x))
y=x.strip()
print(y,len(y))
#10. find(): To check whether a sub-string is available or not
#if found it returns the 1st character index position else it
returns -1.
x="Python is easier than Java"
print(x.find("Java"))
print(x.find("hadoop"))
#11.split():If we split a string, we get a list
x="Good Evening Hyderabad"
y=x.split(" ")
print(y,type(y))
print(y[2])
#ex:
emp="101,Rahul,Manager,60000,pune"
y=emp.split(",")
print(y,type(y))
print(y[1],y[3])
#print():output function--->output stmts in python
x=10
y=20
print(x,y)
print(x,y,sep=",")
print(x,y,sep=" ")
print()
print(x,y,sep="\t") ; print(x,y,sep=":")
print(x,y,sep="-->")
print("\n")
print(x,y,sep="\n")
a=10 ; b=20 ; c=30
print(a,b,c,sep=",")
print(a) ; print(b) ; print(c)
print("Good",end=" ")
print("Morning")
print("Good",end="\t")
print("Morning")
print("Good",end="")
print("Morning")
print("Good",end=" ")
print("Morning",end=" ")
print("Hyderabad")
#input(): For accepting input from the user keyboard
fname=input("Enter the First Name:")
lname=input("Enter the Last Name:")
print(fname+" "+lname)
print(fname,lname,sep=" ")
#Accepting 2 values from the user keyboard and performing
addition
#Note:whatever we are accepting through input function is by
default
taken as string and later we need to convert to respective
Data type.
x=int(input("Enter value of x:"))
y=int(input("Enter value of y:"))
print(x,type(x))
print(y,type(y))
print(x+y)
#There are 2 types of objects in Python:
'''
1.Immutable objects: Objects which doesn’t allow to change or
modify its content are called as immutable objects.
ex: All fundamental data types and tuples
2.Mutable elements : Objects which allow to change or modify
its content are called as mutable objects.
ex: list, set, dictionary.
'''
#ex:
x=[10,20,30,40,50]
print(x)
x[1]=25
print(x)
# Collection Data types: 4 types
'''
1.List ------->[ ]
2.Tuple------->( )
3.Set -------->{ }
4.Dictionary-->{k:v}
'''
#1.List :List is a collection datatype which holds group of
values.
#List Properties:
1.List represented using [ ]
2.List allows both homogeneous(similar) and
heterogeneous(dissimilar) datatypes
x=[10,20,30,40,50]-----> homogeneous elements
y=[101,"Ajay",90870.40]-> heterogeneous elements
3.List allows duplicate elements ex:
x=[10,20,30,40,50,10,20]
4.In List insertion order is followed i.e. the order in which
the elements are inserted in the same order they are stored or
displayed.
5.Each element of a list is identified or accessed by a unique
index.
List supports 2 types of indexes
1. Positive index or forward index-->starts from left to
right--->index starts with 0
2. Negative index or Backward index->starts from right to
left--->index starts with -1.
0 1 2 3 4 ------>forward index or positive
index
x=[10, 20 , 30 , 40 ,50]
-5 -4 -3 -2 -1 ---->backward index or negative
index
6.List is a mutable object i.e. changes or modification are
allowed within a list but elements of a list can be either
mutable or immutable elements.
ex: x=[10,20,30,40,[1,2,3]]
7.List is also created by using list() function.
#Creating a list
x=[10,20,10,30,40,50]
print(x)
print(type(x))
print(id(x))
print(x[0],type(x[0]),id(x[0]))
print(x[1],type(x[1]),id(x[1]))
print(x[2],type(x[2]),id(x[2]))
Output:
[10, 20, 10, 30, 40, 50]
<class 'list'>
2143952768704
10 <class 'int'> 140724047766600
20 <class 'int'> 140724047766920
10 <class 'int'> 140724047766600
#Heterogeneous List
x=[101,"Rahul",80760.40,"pune"]
print(x)
print(x[1][2])
#List Functions
x=[30,10,40,20,50]
print(x)
print(type(x))
print(len(x))
print(sum(x))
print(max(x))
print(min(x))
print(sorted(x))
print(sorted(x,reverse=True))
print(reversed(x)) #It reverses the elements and stores the
result in another object and that object address is returned
#Typecast to list
print(list(reversed(x)))
print(list(reversed(sorted(x))))
x=["Lion","Tiger","Fox","Elephant","rat"]
print(max(x))
print(min(x))
print(sorted(x))
Output :
rat
Elephant
['Elephant', 'Fox', 'Lion', 'Tiger', 'rat']
#String sorting happens based on ASCII Values (First character
of a string)
'''
A-65
B-66
C-67
D-68
.
.
.
.
Z-90
a-97
b-98
c-99
d-100
e-101
f-102
.
.
.
.
.
z-122
'''
#List slicing: Extracting particular elements of a list.
x=[10,20,30,40,50,60]
#Extract---->1st 3 elements
print(x[0:3])#always upper bound is excluded
print(x[3:0])#Empty list---.always slicing in the forward
direction
#Extract---->30,40,50
print(x[2:5])
print(x[5:2])#Empty list
print(x[-4:-1])
#Extract---->30 to 60
print(x[2:6])
print(x[2: ])
print(x[-4: ])
print(x[ :3])
print(x[ : ])
print(x)
print(x[0: ])
print(x[-4:4])
print(x[0:6:2])
print(x[::2])
print(x[::-1]) #reverses the List
#Working with list addresses:
x=[10,20,30,40,50]
y=[10,20,30,40,50]
print(x,id(x))
print(y,id(y))
print(x is y)
print(x == y)
#Note: 2 mutable objects with same content can never have the
same addresses but immutable objects with same content then
only one address.
print(x[0],type(x[0]),id(x[0])
print(y[0],type(y[0]),id(y[0])
#Different ways of creating lists:
#1.using []
#2.using list()
#Creating list using list()
x=list() #Empty list created
print(x)
print(type(x))
print(len(x))
#ex:2
x=list("python")
print(x)
print(type(x))
print(len(x))
#ex:3
'''
x=list("python", "Java") #Error---> bcoz list() takes only one
argument and that argument should be iterable type like
string, list, tuple, set.
print(x)
print(type(x))
print(len(x))
'''
#ex:4
'''
x=list(10) #Error---->bcoz int is not iterable
print(x)
print(type(x))
print(len(x))
'''
#ex:5
x=list([10,20,30,40,50])
print(x)
print(type(x))
print(len(x))
#ex:4
x=list(["python", "Java"])
print(x)
print(type(x))
print(len(x))
#List methods:
#1.append(): for appending an element at the end of the list.
x=[10,20,30,40,50]
print(x,len(x))
x.append(60)
print(x,len(x))
#x.append(70,80) #Error-->bcoz append() takes only one
argument
x.append("Chennai")
print(x,len(x))
x.append((70,80,90))
print(x,len(x))
#2.extend(): for extending a list with the elements of other
list.
y=[1.5,2.5,3.5,4.5,5.5]
x.extend(y)
print(x,len(x))
#3.insert(index,value): for inserting elements at the desired
position
x.insert(2,25)
x.insert(4,"pune")
print(x,len(x))
#4.pop(index):for removing element based on index
x.pop(5)
print(x)
#remove the element---->60
#first find the index of the element 60 using index() method
and delete based on index
#5.index(element): returns the index of an element
print(x.index(60))
x.pop(6)
print(x)
#6.remove(element):removes element based on value
x.remove(50)
x.remove("pune")
print(x)
#7.sort() :For sorting the elements of a list
z=[50,10,40,30,20]
z.sort()
print(z)
#8.reverse():for reversing the elements
a=[1,2,3,4,5]
a.reverse()
print(a)
#9.count(): counts the number of occurrences of an element in
the string
medals=["IND","JAP","AUS","ENG","IND","AUS","ENG","IND","JAP"]
print(medals.count("IND"))
#10.copy() :for duplicating a list
x=[50,60,70,80,90]
y=x.copy()
print(y)