Skip to content

参数

一句话解释

参数 是 named 变量 in 函数 定义 那个 接收 值 (实参) 当 函数 是 called.

用大白话说

参数是 placeholder in 函数定义. 当你 编写 def add(a, b):, a and b are parameters — they are names that will hold the values passed when the function is called.

Parameters can have default values: def greet(name='世界'). If the caller doesn't provide a value, the default is used. Parameters can also be positional or keyword (named) when calling.

The distinction between parameter and argument is: parameters are in the definition, arguments are the actual values passed in the call. This distinction is often blurred in casual usage.

示例

python
# Parameters: a, b (in the definition)
def add(a, b):
    return a + b

# Arguments: 3, 5 (in the call)
result = add(3, 5)
print(result)  # 8

参数 (, b) 是 定义 in 函数 signature. 实参 (3, 5) 是 值 通过 当 calling.

常见混淆

  • 容易混淆的对象: 实参

    关键区别: 参数 是 变量 in 函数 定义. 实参 是 实际 值 通过 到 函数 当 calling 它. 参数 是 placeholders; 实参 是 具体 值.

相关术语

相关资源

相关课程

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误

← 返回术语表