Python Course
Python Course
PYTHON SCRIPTING
MPRASHANT
Why Python?
MPRASHANT
Using #
#This is a singleline comment
Multi-line comment
COMMENTS
"""
first line
your comment here
last line
"""
Variables
MPRASHANT
name="Paul"
WHAT ARE
VARIABLES? print(name)
MPRASHANT
VARIABLES number
RULE No space
No special character
MPRASHANT
name="Paul"
TYPES OF age=30
DATA IN price=25.5
VARIABLES? bol=True/False
MPRASHANT
a=10
b=2
ARITHMETIC print(a+b)
OPERATIONS?
We can perform
+,-,/,*
MPRASHANT
To find the
ARITHMETIC 2^5
OPERATIONS print(2**5)
// AND **
MPRASHANT
2 × (3 + 4)² ÷ 5 - 6
ARITHMETIC
OPERATIONS BODMAS rule
MPRASHANT
PRINTING name="Paul"
STRING
print(f’My name is {name}’)
VARIABLE
String Operations
Strings are immutable
msg="Hello World!"
msg.lower()
STRING msg.upper()
OPERATIONS msg.title()
msg.split()
Lists
Ordered Sequence of different types of values
MPRASHANT
Length of list
len(users)
MPRASHANT
LISTS users.reverse()
SORTING
Temporary sorting of items?
print(users.sorted())
MPRASHANT
LISTS users.pop()
users.pop(2)
MPRASHANT
Getting first two items
users[:2]
LISTS
Getting last 2 items
users.[-2:]
MPRASHANT
sell=[2, 9, 13, 28, 35, 4, 56]
LISTS
Getting sum of items
sum(sell)
Tuples
MPRASHANT
TUPLES Immutable
Ordered
DICTIONARY
car={'brand':'Audi', 'model':'Q3'}
DICTIONARY
car.get('brand')
DICTIONARY
MODIFY How to delete values from a
dictionary?
del car['brand']
MPRASHANT
DICTIONARY Dictionary?
LENGTH len(car)
Sets
Unordered and Unique elements
MPRASHANT
TAKING INPUT
FROM USER...
name = input("What's your name? ")
age = int(input('Your age'))
Conditional Statement
MPRASHANT
IF-ELSE elist=[]
if elist:
print('List is not empty')
else:
print('List is empty')
MPRASHANT
Equal x == 20
Greaterthanorequalto x >= 20
OPERATORS
Lessthanorequalto x <= 50
Not Equal x != 20
print("1st Division")
for i in 1,2,3,4,5:
print(i)
age_info={'Raju':25, 'Sham':30}
active=True
while active:
WHILE msg = input("Your message..")
USEFUL
continue - to stop current iteration
CONCEPTS...
of loop and start next iteration
MPRASHANT
msg=''
while True:
BREAK msg = input("Your message..")
if msg == 'exit':
break
else:
print(msg)
MPRASHANT
users=[]
name=''
while True:
name = input("Your name..")
if msg == 'exit':
CONTINUE break
elif name in users:
print("User already exist")
continue
else:
print(name)
Functions
MPRASHANT
Defining a Function
def myfun():
print("Function is called")
HOW TO MAKE
FUNCTIONS?
Calling a Function
myfun()
MPRASHANT
Defining a Function
def user_info(name, age):
print("Name is "+ name)
ARGUMENTS
print(f"Age is {age}")
PASSING
FUNCTIONS?
Calling a Function
user_info('raju', 30)
MPRASHANT
Defining a Function
def user_info(name, age=20):
print("Name is "+ name)
DEFAULT
VALUES print(f"Age is {age}")
FUNCTIONS?
Calling a Function
user_info('sham')
MPRASHANT
Defining a Function
def user_info(name, age=None):
print("Name is "+ name)
NONE
ARGUMENT if age:
Calling a Function
user_info('sham')
MPRASHANT
RESULT IN
FUNCTIONS? print(addition(10, 20))
MPRASHANT
DYNAMIC
ARGUMENTS
FUNCTIONS
**
MPRASHANT Make a file named cal.py
cal.addition(10, 20)
We can pass list as argument in a function
Object Oriented Programming
Classes
Objects
Classes
A class is a blueprint or a template for
creating objects and it defines the
structure and behaviour of that objects.
Objects
An object is an instance of a class. with its
own unique data and the ability to
perform actions
Objects
Class emp1
name
email
dept
salary
Employees
emp2
Creating Objects
Modifying Attributes
Working with FILES
Writing into a File
Reading from a File (whole content)
Reading from a File (line by line)
Exceptional Handling
Python Modules &
Packages
Python Built-in Module
random
datetime
Dice Game
What is PyPI & PiP
Most powerful and flexible open source
data analysis / manipulation tool
Print the csv file
Print only salary column
Find min and max salary
Find data of employee with
Emp_id 105
Max salary
Find total & average salary of employees
Print full name of employee id 103
Change the salary of Sham to 80000
Remove the data of Leena
Sort the data with salary (min to max)
Add a new column ‘bonus’ with value 10%
of salary
Drop the ‘salary’ column
Working with EMAILS
Weather Checking App
Working with API
Assignment
Create a Calculator Program
Python Program to Run
Linux Commands
MPRASHANT
THANK YOU