Notes 220625
Notes 220625
# 1. Positional arguments
# 2. Keyword arguments
# 3. Default arguments
# 4. Variable length arguments(*args)
# 5. Keyword Variable length arguments(**kwargs)
from platform import processor
def myhobbies(**kwargs):
print("numbers : ",kwargs)
myhobbies()
myhobbies(play='Cricket')
myhobbies(play='Cricket',watch='reels')
myhobbies(play='Cricket',watch='reels',homework='cleaning')
# default arguments
# --> 1. default positional arguments
# --> 2. default keyword arguments
# if argument present --> given value
# if argument absent --> default value
# default argument should present at last
def my_display(empno,empnm,emob=99999999,eaddr="Pune",sal=10000.00,cnt='India'):
print(f"""
Employee number : {empno}
Name of employee : {empnm}
mobile number : {emob}
city : {eaddr}
salary: {sal}
country: {cnt}""")
# my_display(2006,'Rajaram','Beed')
# my_display(2002,'Ranjit',781678133,'Baramati',32452.33)
# my_display(2004,'Alian',445578133,'London',44452.33,'UK')
# my_display(2006,'Rajaram',999978133,'Beed')
# my_display(emob='4455332266',sal=55000.55,empnm='Hari',empno=1002) # keyword
arguments
# Keyword arguments
# no_of_parameters == no_of_arguments
def my_display(empno,empnm,emob,eaddr,sal):
print(f"""
Employee number : {empno}
Name of employee : {empnm}
mobile number : {emob}
city : {eaddr}
salary: {sal}""")
#
my_display(empno=1001,empnm='Shejal',emob='25131313',eaddr='Kolhapur',sal=241313.43
) # keyword arguments
# my_display(emob='4455332266',sal=55000.55,eaddr='Nagpur',empnm='Hari',empno=1002)
# keyword arguments
# Not required to maintain sequence
# key should written for arguments
# positional arguments
# no_of_parameters == no_of_arguments
def my_display(empno,empnm,emob,eaddr,sal):
print(f"""
Employee number : {empno}
Name of employee : {empnm}
mobile number : {emob}
city : {eaddr}
salary: {sal}""")
def my_func():
print("I am very happy")
my_func()
def add(a,b):
ans = a+b
print(ans)
add(10,40)
# function variable
# local, global, nonlocal
a = 10
def outer():
global a
a = 22
def inner1():
a = 700
print(a)
a = 440
def inner2():
print(a)
print(a)
inner2()
print(a)
print(a)
inner1()
print(a)
print("start:",a) # 1 --> 10
outer() # 22,700,440,440,440,22
print("end",a) # end --> 22
import sys
sys.exit(0)
a = 10
def outer():
global a
a = 22
def inner1():
global a
print(a)
a = 440
def inner2():
print(a)
print(a)
inner2()
print(a)
print(a)
inner1()
print(a)
print("start:",a) # 1 --> 10
outer() # 22,22,440,440,440,440
print("end",a) # end --> 440
import sys
sys.exit(0)
a = 10
def outer():
a = 22
def inner1():
nonlocal a
print(a)
a = 440
def inner2():
print(a)
print(a)
inner2()
print(a)
print(a)
inner1()
print(a)
print("start:",a) # 1 --> 10
outer() # 22,22,440,440,440,440
print("end",a) # end --> 10
import sys
sys.exit(0)
a = 10
def outer():
print(a)
def inner1():
a = 44
def inner2():
print(a)
print(a)
inner2()
print(a)
inner1()
print("start:",a) # 1 --> 10
outer() # 10,44,44,44
print("end",a) # end --> 10
import sys
sys.exit(0)
a = 10
def outer():
a = 40
print("2:", a)
a = 77
print("3:", a)
a = 500
print("4:",a)
print("1:",a) # 1 --> 10
outer() # 2,3,4 --> 40,77,500
print("5:",a) # 5--> 10
import sys
sys.exit(0)
a = 10
def outer():
global a
print("2:", a)
a = 77
print("3:", a)
a = 500
print("4:",a)
print("1:",a) # 1 --> 10
outer() # 2,3,4 --> 10,77,500
print("5:",a) # 5--> 500
import sys
sys.exit(0)
# variable --> if local present --> local
# if not local --> global
a = 10
b = 20
def outer():
global a
a = 40
print("2:",a)
a = 500
c = 30
print("3:",a)
print("1:",a) # 1 --> 10
outer() # 2 --> 500
print("4:",a) # 3 --> 10
import sys
sys.exit(0)
a = 10
b = 20
def outer():
a = 40
print("2:",a)
a = 500
c = 30
print("3:",a)
print("1:",a) # 1 --> 10
outer() # 2 --> 500
print("4:",a) # 3 --> 10
import sys
sys.exit(0)
a = 10
def outer():
a = 500
print("2:",a)
print("1:",a) # 1 --> 10
outer() # 2 --> 500
print("3:",a) # 3 --> 10
import sys
sys.exit(0)
a = 10
def outer():
print("2:",a)
print("1:",a) # 1
outer() # 2
print("3:",a) # 3
Assginment
# 1 write a program to REVERSE the content of given string
# input --> welcome | ouput --> emoclew
# 2 write a program to find occurrences of each characters in string
# 3. Write a program for following requirement
# input --> abacacbe | output --> '3a2b2c1e'
# 4. write a program for following requirement
# input 'abacacbe' then output is 'a3b2c2e1'
# 5 write a program to find number of occurrences of each vowel in given string
# s = "Electromagnetics"
# 6 Reverse the given number
# 2754 --> 4572
# 7 Write a program which can compute the factorial of a given numbers
# 5! =5*4*3*2*1
# 8 Write a program for addition of digits of given number
# 2754 --> 18
# 9 Write a program that accepts sequence of lines as input and
# prints the lines after making all characters in the sentence capitalized.
# input --> Hello world Practice makes perfect
# output--> HELLO WORLD PRACTICE MAKES PERFECT