为什么 str.split 不接受关键字参数? [英] Why does str.split not take keyword arguments?
问题描述
我遇到了这个 - 在我看来 - 奇怪的行为:
I came across this - in my view - strange behaviour:
"a b c".split(maxsplit=1)
TypeError: split() takes no keyword arguments
为什么 str.split() 不接受关键字参数,即使它有意义?我在 Python2 和 Python3 中都发现了这种行为.
Why does str.split() not take keyword arguments, even though it would make sense? I found this behavior both in Python2 and Python3.
推荐答案
str.split()
是 CPython 中的本机函数,因此表现出描述的行为 此处:
str.split()
is a native function in CPython, and as such exhibits the behavior described here:
CPython 实现细节:一个实现可能提供内置的位置参数没有名称的函数,即使它们出于文档目的而命名",因此不能由关键字提供.在 CPython 中,情况就是这样在 C 中实现的函数使用 PyArg_ParseTuple()
来解析它们的参数.
CPython implementation detail: An implementation may provide built-in functions whose positional parameters do not have names, even if they are ‘named’ for the purpose of documentation, and which therefore cannot be supplied by keyword. In CPython, this is the case for functions implemented in C that use
PyArg_ParseTuple()
to parse their arguments.
这篇关于为什么 str.split 不接受关键字参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!