如何检查str int列表和元组? [英] how to check str int list and tuple?
本文介绍了如何检查str int列表和元组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有一个包含str int列表和tuple的文件.我想将它们放在其他列表中.
there is a file include str int list and tuple. I want to put them in different list.
这是我的示例代码:
for word in file:
if type(word) == int:
......
if type(word) == list:
......
我可以检查int是否使用type(word)== int
I can check int use type(word) == int
但是我不能在代码中使用'type(word)== list'.
but I can't use 'type(word) == list' in my code.
那么,如何检查文件是列表"还是元组"?
so, How to check a file is 'list' or 'tuple'?
推荐答案
这应该有效-
for word in file:
if isinstance(word, int):
...
elif isinstance(word, list):
...
elif isinstance(word, tuple):
...
elif isinstance(word, str):
...
这篇关于如何检查str int列表和元组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文