Error:
TypeError: list indices must be integers or slices, not str
error code block:
AA is a set of list and dict data
The function insert receives two parameters, * args, * * kwargs
I hope to pass the list AA to * args
But in the execution of the program, a title display error was reported
first of all, the basic concepts of * args and * kwargs:
For * args and * * kwargs, we can call them parameter groups in functions, but they are different
1: * functions of args: – – – receive n position parameters and convert them into tuple form
2: The function of * * kwargs is to receive n keyword parameters and convert them into dict form
3: The location parameter must precede the keyword parameter, that is, (* args, * * kwargs)
problem analysis:
A * sign before the parameter AA indicates that it is an assembled tuple, otherwise Python will think AA is a positional parameter
So the program can run as expected
Similar Posts:
- How to Solve Python Error : **kwargs and takes 1 positional argument but 2 were given
- Python Standard Library: functools (cmp_to_key, lru_cache, total_ordering, partial, partialmethod, reduce, sing…
- Django path Error: ‘Specifying a namespace in include() without providing an app_name ‘
- TypeError: ‘list’ object cannot be interpreted as an integer
- PaddlePaddle Error: ‘map’ object is not subscriptable
- Flask Accessing an interface that returns a dictionary error: The view function did not return a valid response. The return type must be a string, tuple, Response instance, or WSGI callable, but it was a dict.
- Summary of common functions of urllib.parse in Python 3
- Convert Object to List>, avoiding Unchecked cast: ‘java.lang.Object’ to ‘java.util.List
- Usage of within group in Oracle
- Python3: list dict set [UNK]unhashable type