字典键类型混淆为Instance python
我无法理解接下来的执行。我期待着不同的结果字典键类型混淆为Instance python,python,dictionary,Python,Dictionary,我无法理解接下来的执行。我期待着不同的结果 >>> f = {'ms':'ma'} >>> isinstance(f['ms'], type(str)) False >>> isinstance(f['ms'], type(dict)) False >>> type(f['ms']) <class 'str'> >f={'ms':'ma'} >>>isinstance(f['ms'],类型(str)) 假的
>>> f = {'ms':'ma'}
>>> isinstance(f['ms'], type(str))
False
>>> isinstance(f['ms'], type(dict))
False
>>> type(f['ms'])
<class 'str'>
>f={'ms':'ma'}
>>>isinstance(f['ms'],类型(str))
假的
>>>isinstance(f['ms'],类型(dict))
假的
>>>类型(f['ms'])
我想你只是想要这个:
>>> f = {'ms':'ma'}
>>> isinstance(f['ms'], str)
True
您不需要
类型(str)
我想您只需要这个:
>>> f = {'ms':'ma'}
>>> isinstance(f['ms'], str)
True
您不需要每次返回type(str)
type(str)
和type(dict)
时都返回type
,因此您要检查对象是否是type
的实例,而它们不是
如果要检查某个内容是否为字符串,请使用
isinstance(f['ms'], str)
不是
如果您想测试某个东西是否是dict,可以使用
isinstance(f['ms'], dict)
不是
type(str)
和type(dict)
每次返回type
,因此您要检查对象是否为type
的实例,而不是
如果要检查某个内容是否为字符串,请使用
isinstance(f['ms'], str)
不是
如果您想测试某个东西是否是dict,可以使用
isinstance(f['ms'], dict)
不是
type(str)
返回type
,因此您要检查f['ms']
是否是type
的实例,而不是str
的实例。如果要检查某个内容是否是字符串,请使用isinstance(f['ms'],str)
type(str)
返回type
,因此您要检查f['ms']
是否是type
的实例,而不是str
的实例。如果要检查某个内容是否为字符串,请使用isinstance(f['ms'],str)
。