小编spi*_*tty的帖子

为什么我得到TypeError"类型'类型的参数'不可迭代"?

我试图在测试之后将一些键添加到我的字典中,如果它们已经是现有键.但是每次我得到它,我似乎都无法进行测试TypeError "argument of type 'type' not iterable.

这基本上是我的代码:

dictionary = dict
sentence = "What the heck"
for word in sentence:
      if not word in dictionary:
             dictionary.update({word:1})
Run Code Online (Sandbox Code Playgroud)

我也试过,if not dictionary.has_key(word)但它也没用,所以我真的很困惑.

python testing dictionary if-statement typeerror

2
推荐指数
1
解决办法
2万
查看次数

标签 统计

dictionary ×1

if-statement ×1

python ×1

testing ×1

typeerror ×1