def getUser(): def关键字定义了一个函数
关键字实参
def getUser(userName, userAge):
getUser(userName='张三', userAge=18)
默认值
def getUser(userName, userAge=18): 如果没有传年龄过来默认年龄等于18
def print_models(unprinted_designs, completed_models): """ Simulate printing each design, until none are left. Move each design to completed_models after printing. """ completed_models = unprinted_designs[:] while unprinted_designs: current_design = unprinted_designs.pop() print(f"Printing model: {current_design}") completed_models.append(current_design) def show_completed_models(completed_models): """Show all the models that were printed.""" print("\nThe following models have been printed:") for completed_model in completed_models: print(completed_model) unprinted_designs = ['phone case', 'robot pendant', 'dodecahedron'] completed_models = [] print_models(unprinted_designs, completed_models) show_completed_models(completed_models) ---------------------------------------------------------- Printing model: dodecahedron Printing model: robot pendant Printing model: phone case The following models have been printed:
经过测试,python和Java一样只有值传递没有引用传递
def make(*args1, **args2) *任意数量实参 **任意数量关键字实参
import pizza 导入模块
pizza.make() 使用其他模块的方法
from moudle_name import function_name1,function_name2,function_name3 导入某个模块的具体方法 可以导入多个
from moudle_name import function_name1 as fun1 用as去给这个方法起别名
import moudle_name as m1 用as给模块起别名
from moudle_name import * 导入这个模块所有的方法