print("------------------------------- 函数调用的参数传递 ------------------------------------")defcalc(a, b):# 函数定义。 a, b 称为形式参数,简称 形参 ,形参 的位置是在函数的定义处
c = a + b
return c
result = calc(10,20)# 函数调用。 10, 20 称为实际的参数,简称 实参 ,实参 的位置是在函数的调用处。 位置实参print(result)
res = calc(b=10, a=20)# 关键字实参。 = 左侧的变量的名称称为 关键字参数print(res)
运行结果:
D:\Environment\Python\Python311\python.exe D:\Environment\PythonWorks\learnpython\马士兵Python\第10章_水晶球不调用不动\P88_87.函数调用的参数传递_位置实参_关键字实参.py
------------------------------- 函数调用的参数传递 ------------------------------------3030
Process finished with exit code 0