2. : INTRODUCTION :
Early in 1980 by Guido Van Rossum.
High-level, Hybrid Object Oriented, Scripting language.
Open-source.
Areas: Biology, Data Science, Geography, Language Processing etc.
Framework like SciPy, Django, Pyramid, Flask, Bottle, PyGame, Ipython, Pandas.
Standard library supports HTML, XML, JSON, Email, FTP etc.
2
3. : Features :
• Simple, Easy to learn.
• Free and Open Source.
• High-level, Portable.
• Interpreted, Object-Oriented.
• Extensible, Embeddable.
• Extensive Libraries.
3
4. : Java vs Python :
Dynamic vs Static Typing.
Object Orientation Methodology.
Braces vs Indentation.
Speed and Portability.
Distributed vs Concentrated.
4
5. : Java vs Python :
::: Example :::
• Java:
public class A
{
public static void main(String args[])
{
System.out.println(“Hello World”);
}
}
• Python:
>>>print (“Hello World”)
5
6. : IO and Variables:
Take input as:
var_name = input(“Enter
Name: ”)
>>> Enter Name: Sohil
Print output:
print (var_name)
>>> Sohil
var_name = input(“Enter Name: ”)
>>> Enter Name: Sohil
>>> print (type(var_name))
>>> <class ‘str’>
6
9. ::: Operator :::
• Operation on String:
a = “Hello, ”
b = “How are you?”
c = a + b
print(c) #Hello, How are you?
• Operation on Numbers:
a = 6
b = 7
print(c) # 13
Expression = Operator(s) + Operand(s).
9
10. : Conditional :
• if statement
• if-else statement
• if – elif – else statement
a = int(input(“Enter Number: ”))
if a%2==0:
print(“Even”)
else:
print(“Odd”)
10
11. ::: Looping :::
‘for loop’
for i in range(1,6):
print(i + end = “ ”)
else:
print(“End”)
>>> 1 2 3 4 5 End
‘while loop’
a = 1
while(a<5):
print(a + “ ”)
a++
>>> 1 2 3 4
11
12. : Function :
• Group of statement that together performs a specific task.
• Defined using ‘def’ keyword.
• Syntax: def functionName():
# Function Body
• Ex: def printName(): # Function Definition
print(“Sohil”) # Function Body
printName() # Function Call
12
13. ::: Object Orientation :::
• Class: User-defined data type (think of), logical.
• Object: Physical reality of class.
person1(Object) Person(Class)
first_name(Field)
last_name(Field)
Sohil
Sundaram
printName()(Method)
13
14. ::: OOPS Example :::
Class Table: # Class Declaration
def printTable(self): # Class Method
x = 5
for i in range(1,11,2): # For loop
print(x*i + end = ‘ ’)
pT = Table( ) # Object Creation
pT.printTable( ) # Method Calling
Output: 5 15 25 35 45
14
15. :: Inheritance ::
• Phenomena of Object Oriented Language.
• Base class is ‘object’.
• Syntax: class SuperClass: # Parent Class
pass
class SubClass(SuperClass): # Child Class
pass
* pass is used to describe that block contains nothing and it is just for demonstration.
15
16. : Inheritance Example :
16
class Employee(Person):
pass
emp = Person(“Sohil”)
print(emp.getName( ))
emp = Employee(“Sundaram”)
print(emp.getName( ))
class Person(object):
def __init__(self, name):
self.name = name
def get Name(self):
return self.name
def isEmployee(self):
return false
17. :: Conclusion ::
• Accessible for beginners.
• Growing Demand.
• Used in mass functional areas like Google, YouTube, Facebook etc.
• Replacing Java in many areas.
• Rich and Diverse Library.
17