TypeError: get() takes no keyword arguments

前端 未结 3 871
后悔当初
后悔当初 2020-12-05 06:05

I\'m new at Python, and I\'m trying to basically make a hash table that checks if a key points to a value in the table, and if not, initializes it to an empty array. The off

3条回答
  •  有刺的猬
    2020-12-05 07:00

    Due to the way the Python C-level APIs developed, a lot of built-in functions and methods don't actually have names for their arguments. Even if the documentation calls the argument default, the function doesn't recognize the name default as referring to the optional second argument. You have to provide the argument positionally:

    >>> d = {1: 2}
    >>> d.get(0, default=0)
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: get() takes no keyword arguments
    >>> d.get(0, 0)
    0
    

提交回复
热议问题