#方法1 # ~ from pizza1 import make_pizza # ~ make_pizza(16,'pepperoni') # ~ make_pizza(12,'musheooms','green peppers') #方法2 # ~ import pizza1 # ~ pizza1.make_pizza(16,'pepperoni') # ~ pizza1.make_pizza(12,'musheooms','green peppers') #使用as给函数指定别的名字 # ~ from pizza1 import make_pizza as usa # ~ usa(16,'pepperoni') # ~ usa(12,'musheooms','green peppers') import pizza1 as fn fn.make_pizza(16, 'pepperoni') from pizza1 import * make_pizza(16, 'pepperoni') make_pizza(12, 'musheooms', 'green peppers')
#--> making pizzas, importing pizza1 # 1st approach to importing - # module_name.function_name() import pizza1 pizza1.make_pizza(16, 'pepperoni') pizza1.make_pizza(12, 'mushrooms', 'green peppers', 'extracheese') print("...") # Import a specific function from a module - # from module_name import function_name, function_1, etc # You can import as many functions as wanted. from pizza1 import make_pizza make_pizza(16, 'pepperoni') make_pizza(12, 'mushrooms', 'green peppers', 'extracheese') print("...") #--> Using 'as' to Give a Function an alias # from module_name import function_name as fn from pizza1 import make_pizza as mp mp(16, 'pepperoni') mp(12, 'mushrooms', 'green peppers', 'extracheese') print("...")
import pizza1 pizza1.make_pizza(10, 'pepermini') pizza1.make_pizza(12, 'mushrooms', 'green peppers', 'extra cheese') from pizza1 import make_pizza make_pizza(10,'pepermini') make_pizza(12, 'mushrooms', 'green peppers', 'extra cheese') from pizza1 import make_pizza as mp mp(16,'pepermini') mp(14, 'mushrooms', 'green peppers', 'extra cheese') # Using as to Give a Module an Alias import pizza1 as p p.make_pizza(15,'pepermini') p.make_pizza(13, 'mushrooms', 'green peppers', 'extra cheese') # Importing All Functions in a Module from pizza1 import * make_pizza(14, 'mushrooms', 'green peppers', 'extra cheese')