【发布时间】:2021-05-17 09:24:10
【问题描述】:
运行下面的代码时出现以下错误。我可以在屏幕上清楚地打印*strs 的值,它显示为字符串。但是,当我执行type(*strs) 时,它会抛出TypeError: type.__new__() argument 2 must be tuple, not str。有人可以解释这种行为吗?
strs = ["flower","flood","flight"]
print(*strs)
print(type(strs))
print(type(*strs))
输出:
Traceback (most recent call last):
print(type(*strs))
TypeError: type.__new__() argument 2 must be tuple, not str
flower flood flight
<class 'list'>
Process finished with exit code 1
【问题讨论】:
-
请添加纯python标签
-
他的问题比这更复杂一点。具体来说,他想解释“type.__new__() argument 2 must be tuple, not str”的含义,以及为什么他的代码会导致该特定错误。他不是在问星星是什么意思。
标签: python-3.x string tuples typeerror