import factorial
After importing the function, we can call the function factorial in the following way:
import factorial print(factorial.compute_factorial(5)) print(n)
Here, the function factorial.compute_factorial() indicates the compute_factorial() function within the file factorial.py. The output of the above program will be:
120
Please note that we can also use the “from
from factorial import compute_factorial print(compute_factorial(5))
We can also import a module using the statement “import
import factorial as fact print(fact.compute_factorial(5))
Here, the factorial module will be imported and the module will be available in the program as fact. So, we will need to use fact.compute_factorial() to call the function.
Similarly, we can also import a function or value from a module in the following way:
from factorial import compute_factorial as compute_fact print(compute_fact(5))
Here, the compute_factorial() function will be imported in the new program and will be available as compute_fact() function. So, print(compute_fact(5)) will print the following output:
120








































0 Comments