Python:期望缩进块 [英] Python: Expected an indented block

查看:825
本文介绍了Python:期望缩进块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为所有内容都在这里缩进,但我在 else:语句中得到 IndentationError:预期缩进块。我在这里犯了一个明显的错误吗?

I thought everything was properly indented here but I am getting an IndentationError: expected an indented block at the else: statement. Am I making an obvious mistake here?

def anti_vowel(text):
    new_string = ""
    vowels = "aeiou"
    for letter in text:
       for vowel in vowels:
           if (lower(letter) == vowel):
               #do nothing
           else:
               #append letter to the new string
               new_string += letter
    return new_string


推荐答案

不执行任何操作转换为使用传递关键字来填充其他空块(这是不允许的)。有关详细信息,请参阅官方文档

Do nothing translates to using the pass keyword to fill an otherwise empty block (which is not allowed). See the official documentation for more information.

def anti_vowel(text):
    new_string = ""
    vowels = "aeiou"
    for letter in text:
       for vowel in vowels:
           if (lower(letter) == vowel):
               #do nothing
               pass
           else:
               #append letter to the new string
               new_string += letter
    return new_string

这篇关于Python:期望缩进块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆