Passing Arguments to Function in Python

Passing arguments to Function in Python programming. Functions are used to divide a large program into sub-programs for easy control. All these sub-programs are called sub-functions of the program.

Program Passing Argument to Parameter

Program

def fun(arg): #'fun()' is name of Function and passing here Argument to
    print("This is "+ arg +" Function") #Parameter 'arg' and printing.
print("Before Calling Function")
fun("Parameterized") #calling and passing Argument to Parameter.
print("After Calling Function")
Output
Before Calling Function
This is Parameterized Function
After Calling Function

Program Passing Arguments to Parameters

Program

def fun(): #'fun()' is name of function.
    print("This is Simple Function")
def fun1(a, b): #passing arguments here to parameters.
    i = a #assigning 'a' value to 'i'.
    j = b #assigning 'b' value to 'j'.
    k = i + j #adding 'i' and 'j' values and assigning to 'k'.
      #U also Direct write like 'k = a + b'.
    print("The Sum is: ", k)
def fun2(): #'fun2()' is name of function.
    print("This is Another Simple Function")
fun() #calling 'fun()' function.
fun1(5, 6) #calling and passing arguments to parameter.
fun2() #calling 'fun2()' function.
Output
This is Simple Function
The Sum is: 11
This is Another Simple Function

Program Passing Arguments to Parameters Another Method

Program

def fun(i, j): #passing here arguments to parameters.
    print("The Passed i value is: ", i) #and printing.
    print("The Passed j value is: ", j)
def fun2(x, y, z): #passing here arguments to parameters.
    print("The Passed x value is: ", x) #and printing.
    print("The Passed y value is: ", y)
    print("The Passed z value is: ", z)
a = 5
b = 65
c = 'C'
fun(a, b) #calling and passing arguments to parameters.
fun2(a, b, c) #calling and passing arguments to parameters.
Output
The Passed i value is: 5
The Passed j value is: 65
The Passed x value is: 5
The Passed y value is: 65
The Passed z value is: C

Program Passing Arguments to Parameters and Repassing
Program

def set(name, roll, sec): #passing here arguments to parameters.
    n = name
    r = roll
    s = sec
    show(n, r, s) #calling and passing arguments to parameters.
def show(name, roll, sec): #passing here arguments to parameters.
    print("My Name is: ", name)
    print("My Roll Number is: ", roll)
    print("My Class section is: ", sec)
print("Before Calling Functions")
set("HiLaLs", 12012, 'B') #calling and passing arguments to parameters.
print("After Calling Functions")
Output
Before Calling Functions
My Name is: HiLaLs
My Roll Number is: 12012
My Class section is: B
After Calling Functions