有关函数中参数命名问题 Python

img

max不是关键字嘛,为什么可以作为参数嘞,不是有一个max函数嘛

在函数内部max是局部变量,只要函数内不用到max函数是不要紧的

但是如果用了max变量,max()就用不了,函数名的优先级没变量名高,如:

max(1,2,3)
3
max = 5
max
5
max(1,2,3)
Traceback (most recent call last):
File "<pyshell#10>", line 1, in
max(1,2,3)
TypeError: 'int' object is not callable
del max
max

max(1,2,3)
3

是个函数, 不是保留关键字

import keyword
keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']

这些是严格不能作为变量的。