Code
#function1 def cube(x) : return x**3 #function2 def maxVal(x,y) : if x > y : return x else : return y print (cube(3)) print (maxVal(12,22))
Lets see how to import functions in another python script.
There are 2 importing methods
- import a single function
- import all functions under a "namespace"(python script)
- import a single function
from mylib import factorial print (factorial(4))
So we can call function directly.
Other way
import mylib print (mylib.factorial(4))
In this method there may be some anomalies if we are going to import 2 functions with same name and signature in different scripts.
0 comments:
Post a Comment