Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/347.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.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
应为缩进块python错误_Python_Indentation_Python 3.6 - Fatal编程技术网

应为缩进块python错误

应为缩进块python错误,python,indentation,python-3.6,Python,Indentation,Python 3.6,我是Python新手,所以对它了解不多。但是我知道缩进的基本知识,我无法解决以下代码中预期缩进块的错误 meal =["egg","milk","spam","tomato"] for item in meal: if item =="spam": nasty_food =item break if nasty_food: print("there is nasty food") 必须使用一致性缩进代码,因为这在Python中是必须做的 不要为

我是Python新手,所以对它了解不多。但是我知道缩进的基本知识,我无法解决以下代码中预期缩进块的错误

meal =["egg","milk","spam","tomato"]

for item in meal:
    if item =="spam":
        nasty_food =item
        break

if nasty_food:
   print("there is nasty food")

必须使用一致性缩进代码,因为这在Python中是必须做的

不要为每个函数使用不同数量的空格。这将引导您解决新问题

请尝试以下代码:

meal = ["egg", "milk", "spam", "tomato"]

for item in meal:
    if item == "spam":
        nasty_food = item
        break

if nasty_food:
    print("there is nasty food")

从视觉上看,我在您发布的代码中没有看到缩进问题。请确认您没有混淆制表符和空格,因为这也可能导致缩进问题。

请附上源文件。我在您的代码中找不到任何预期错误。重新检查您的代码,确保不会混淆空格和制表符。感谢您的关注,我运行了您的代码,但我有相同的错误此代码是较大部分的一部分,还是您正试图运行此代码?因为,我在运行它时没有遇到任何问题。好吧,它解决了我不知道错误在哪里,但是我重新编写了代码,它工作了!注意混合标签和空格。每个像样的文本编辑器都应该有一个将制表符转换为空格的选项,这样您就不会出现诸如错误缩进代码之类的难以发现的问题。