Python - 函数变量中没有定义名称?

Python - Name is not defined in a function variable?

我似乎搞砸了最基本的事情。我有:

def function(a, b, c):
    return 'hi'

print(function(a,b,c)) 对每个变量产生 NameError

这是什么原因?

函数的参数名称是局部变量,它们不能用作全局名称。 abc 仅存在于函数的 内部 ,并接收传递给函数的值。

您需要创建新变量或在调用函数时使用文字值:

print(function(1, 2, 3))

会起作用,因为 123 是传递给函数的实际值。