实参
一句话解释
实参 是 实际 值 通过 到 函数 当 calling 它, filling 函数's 参数.
用大白话说
实参是 具体值 你通过到 函数当 calling 它. In add(3, 5), the numbers 3 and 5 are arguments. They fill the function's parameters.
Python supports several types of arguments:
- Positional arguments — matched by position:
添加(3, 5) - Keyword arguments — matched by name:
添加(=3, b=5) - Default arguments — used when not provided:
def greet(name='世界') - *args — collects extra positional arguments into a tuple
- **kwargs — collects extra keyword arguments into a dict
The distinction: parameters are the names in the definition; arguments are the values in the call.
示例
python
def func(a, b=10, *args, **kwargs):
print(a, b, args, kwargs)
func(1) # 1 10 () {}
func(1, 2) # 1 2 () {}
func(1, 2, 3, 4) # 1 2 (3, 4) {}
func(1, 2, x=100, y=200) # 1 2 () {'x': 100, 'y': 200}实参 能 是 positional, keyword, 默认, *args (extra positional), or **kwargs (extra keyword).
常见混淆
容易混淆的对象: 参数
关键区别: 实参 是 值 通过 当 calling 函数. 参数 是 变量 name in 函数 定义 那个 接收 实参. 实参 是 具体; 参数 是 placeholders.
相关术语
相关资源
相关课程
- 函数
函数 实参.
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。