【发布时间】:2021-11-25 21:49:02
【问题描述】:
x = ['string1','string1','string1']
如何检查x 的类型是否为List[str]?
if type(x) != List[str]:
raise ValueError("x should be list of str")
这个 if 条件返回 True 和 raise Error 但不应该。
【问题讨论】:
-
您要静态检查还是在运行时检查?
-
我想这个问题已经在这里回答了stackoverflow.com/questions/13252333/…
-
好吧,
type(x)返回list而不是List[str] -
我认为有一些解决方案无需遍历列表中的所有值
标签: python if-statement typeerror valueerror