Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在编写一些代码来接收具有可变数量参数的函数。我也有这些参数的列表(但函数需要单独的参数,而不是一个列表)。有没有办法将此列表转换为函数可能喜欢的形式的参数(遗憾的是,它们不能只转换为字符串)?
是的,只需在列表前加上 a*即可解压:
*
args = [1, 2, 3] foo(*args) # equivalent to foo(1, 2, 3)
Python 教程中提供了更多详细信息。