Python: By: Deepak Malusare
Python: By: Deepak Malusare
By : Deepak Malusare
Introduction
• 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.
• etc...
Limitations of Python:
• Performance wise not up to the
mark because it is interpreted
language.
• Not using for mobile Applications
Flavors of Python:
• CPython:
It is the standard flavor of Python. It can be used to work with C language
Applications
• Jython or JPython:
It is for Java Applications. It can run on JVM
• IronPython:
It is for C#.Net platform
• PyPy:
The main advantage of PyPy is performance will be improved because JIT
compiler is available inside PVM.
• RubyPython
For Ruby Platforms
• AnacondaPython
It is specially designed for handling large volume of data processing.
Python Versions:
• Python 1.0V introduced in Jan 1994
• Python 2.0V introduced in October 2000
• Python 3.0V introduced in December 2008
• Note: Python 3 won't provide backward
compatibility to Python2
• i.e there is no guarantee that Python2 programs
will run in Python3.
Pending Topics
Pending Topics
Complex Data Type
• A complex number is of the form
str type:
• str represents String data type.
• A String is a sequence of characters enclosed
within single quotes or double quotes.
s1='durga'
• s1="durga"
Slicing of Strings:
• slice means a piece
• [ ] operator is called slice operator, which can be
used to retrieve parts of String. In Python Strings
follows zero based index.
• The index can be either +ve or -ve.
• +ve index means forward direction from Left to
Right
• -ve index means backward direction from Right
to Left
Example
print("durga"+"soft")
print("durga"*2)
len() in-built function:
• We can use len() function to find the number of
characters present in the string.
Eg:
s='durga'
print(len(s))
Write a program to access each character of string in
forward and backward direction by using while loop
s="Learning Python is very easy !!!“
n=len(s)
i=0
print("Forward direction")
while i<n:
print(s[i],end=' ')
i +=1
print("Backward direction")
i=-1
while i>=-n:
print(s[i],end=' ')
i=i-1
Alternative ways:
s="Learning Python is very easy !!!“
print("Forward direction")
for i in s:
print(i,end=' ')
print("Forward direction")
for i in s[::]:
print(i,end=' ')
print("Backward direction")
for i in s[::-1]:
print(i,end=' ')
Checking Membership:
• We can check whether the character or string is
the member of another string or not by using in
and not in operators
s='durga'
print('d' in s)
print('z' in s)
Check substring
s=input("Enter main string:")
subs=input("Enter sub string:")
if subs in s:
print(subs,"is found in main string")
else:
print(subs,"is not found in main string")
Comparison of Strings:
We can use comparison operators (<,<=,>,>=) and equality operators(==,!
=) for strings. Comparison will be performed based on alphabetical
order.
Eg:
s1=input("Enter first string:")
s2=input("Enter Second string:")
if s1==s2:
print("Both strings are equal")
elif s1<s2:
print("First String is less than Second String")
else:
print("First String is greater than Second String")
• Replacing a string with another string:
s.replace(oldstring,newstring)
inside s, every occurrence of oldstring will be
replaced with newstring.
Eg1:
s="Learning difficult Python is very difficult“
s1=s.replace("difficult","easy")
print(s1)
Changing case of a String:
We can change case of a string by using the following methods.