How to check if a variable is a dictionary in python
This question already has an answer here:
if type(ele) is dict
或者使用isinstance(ele,dict),你可以使用,如果你使用了子类型的字典,
d = {'abc':'abc','def':{'ghi':'ghi','jkl':'jkl'}}
for ele in d.values():
if isinstance(ele,dict):
for k, v in ele.items():
print(k,' ',v)
链接地址: http://www.djcxy.com/p/54218.html
上一篇: 为什么使用isinstance()而不是type()?
下一篇: 如何检查变量是否是Python中的字典