Class 12: Using Libraries 3

By: Archana Shukla and Rajesh Shukla

Method:3
importing all the function at the same time

from module_name import *

filename: m3.py

from example1 import *


# 1(without input)
sum(10,20)
prod(10,20)
diff(10,20)

#2(using user input)
a=int(input("Enter 1st no "))
b=int(input("Enter 2nd no "))
sum(a,b)
prod(a,b)
diff(a,b)

Output:

sum = 30
prod = 200
diff = 10
Enter 1st no 2
Enter 2nd no 3
sum = 5
prod = 6
diff = 1
>>>

Method:4
importing the function with different names

from module_name impory function_name as user_defined_name

filename: m4.py

from example1 import sum as s
from example1 import prod as p
from example1 import diff as d

#1(without input)

s(10,20)
p(10,20)
d(10,20)

#2(using user input)

a=int(input("Enter 1st no "))
b=int(input("Enter 2nd no "))
s(a,b)
p(a,b)
d(a,b)

Output:

sum = 30
prod = 200
diff = 10
Enter 1st no 2
Enter 2nd no 6
sum = 8
prod = 12
diff = 4
>>>