在研究python中的参数和参数的那天结束时,我终于做出了以下结论
功能定义中的参数顺序
def foo ( non-optional parameters , optional parameters , *args , **kwargs):
函数调用中的参数顺序
foo( non-keyword arguments , keyword arguments )
只想知道python世界中是否有任何异常.... 此外,如果有任何其他类型的参数/参数,请做评论......
谢谢!
答案 0 :(得分:1)
参数匹配语法 总结了调用特殊参数匹配模式的语法。 函数参数匹配表单语法位置解释
用于定义函数......
答案 1 :(得分:0)
Python Language Reference描述了语言的语法和“核心语义”。它很简洁,但试图准确而完整。在那里,您可以使用修改后的BNF grammar表示法找到词法分析和语法的描述。
通常所有Python实现都遵循此语法。因此,这个语法应该没有例外。如果是,您应该参考特定于实现的文档。
decorated ::= decorators (classdef | funcdef)
decorators ::= decorator+
decorator ::= "@" dotted_name ["(" [argument_list [","]] ")"] NEWLINE
funcdef ::= "def" funcname "(" [parameter_list] ")" ":" suite
dotted_name ::= identifier ("." identifier)*
parameter_list ::= (defparameter ",")*
( "*" identifier ["," "**" identifier]
| "**" identifier
| defparameter [","] )
defparameter ::= parameter ["=" expression]
sublist ::= parameter ("," parameter)* [","]
parameter ::= identifier | "(" sublist ")"
funcname ::= identifier
call ::= primary "(" [argument_list [","]
| expression genexpr_for] ")"
argument_list ::= positional_arguments ["," keyword_arguments]
["," "*" expression] ["," keyword_arguments]
["," "**" expression]
| keyword_arguments ["," "*" expression]
["," "**" expression]
| "*" expression ["," "*" expression] ["," "**" expression]
| "**" expression
positional_arguments ::= expression ("," expression)*
keyword_arguments ::= keyword_item ("," keyword_item)*
keyword_item ::= identifier "=" expression