标题: Python函数原型中斜杠/与星号*的含义 https://scz.617.cn/python/202303111218.txt Q: https://dnicolodi.github.io/python-siphash24/ 该页有个函数原型 -------------------------------------------------------------------------- siphash24.siphash24(data=b'', /, *, key=b'') data initial chunk of data to hash, which must be bytes-like object. It can be passed only as positional argument. key key for keyed hashing, which must be a bytes-like object. The passed key can be up to 16 bytes in lenght. Shorter keys are zero padded to 16 bytes. It can be passed only as a keyword argument. -------------------------------------------------------------------------- data与key我知道啥意思,也知道如何正确指定它们,但/和*分别是什么意思? A: ChatGPT 2023-03-11 In Python, / and * are special symbols used to separate positional-only arguments, positional-or-keyword arguments, and keyword-only arguments. Here is what each of these symbols means: /: Separates positional-only arguments from other types of arguments. Any arguments listed before the / symbol can only be specified positionally and cannot be passed as keyword arguments. This feature was introduced in Python 3.0 and is used to define functions with argument lists that cannot be changed in backward-incompatible ways. *: Separates positional-or-keyword arguments from keyword-only arguments. Any arguments listed after the * symbol can only be passed as keyword arguments and cannot be specified positionally. This feature was introduced in Python 3.0 and is used to define functions with flexible argument lists that can accept any combination of positional and keyword arguments. In the case of siphash24.siphash24(data=b'', /, *, key=b''), the / indicates the end of positional-only arguments, which means that the data argument must be specified positionally (i.e., without a keyword). The * indicates the start of keyword-only arguments, which means that the key argument must be specified using a keyword. 简而言之,函数原型中/之前的都是"positional-only arguments",*之后的都是 "keyword-only arguments",实际调用函数时不要出现/与*。