Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
字典键类型混淆为Instance python_Python_Dictionary - Fatal编程技术网

字典键类型混淆为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)