本文介绍了Python:需要一个缩进块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我认为这里的所有内容都已正确缩进,但我在 else: 语句中收到 IndentationError: expected an indented block.我在这里犯了一个明显的错误吗?
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 转换为使用 pass
关键字来填充原本为空的块(这是不允许的)).有关详细信息,请参阅官方文档.
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:需要一个缩进块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!