缩进错误
Identation Error
我遇到了 "IndentationError: unindent does not match any outer indentation level" 的错误,我已经尝试使用命令并更改 space 和选项卡,但错误仍然继续出现,我已经尝试了所有我读过的内容论坛,但错误仍然出现在同一部分,请帮助
错误部分:
bullets.update()
^
代码:
def update_bullets(bullets):
"""Update position of bullets and gets rid of old bullets"""
#Update bullet position
bullets.update()
# Get rid of bullets that had dissapeared
for bullet in bullets.copy():
if bullet.rect.bottom <= 1:
bullets.remove(bullet)
print(len(bullets))
正确缩进的代码应如下所示:
def update_bullets(bullets):
"""Update position of bullets and gets rid of old bullets"""
#Update bullet position
bullets.update()
# Get rid of bullets that had dissapeared
for bullet in bullets.copy():
if bullet.rect.bottom <= 1:
bullets.remove(bullet)
print(len(bullets))
Python 代码始终需要适当的缩进。空格很重要(与 C 不同)!
我建议查看 this tutorial 以获得有关 Python 的基本教程。
我遇到了 "IndentationError: unindent does not match any outer indentation level" 的错误,我已经尝试使用命令并更改 space 和选项卡,但错误仍然继续出现,我已经尝试了所有我读过的内容论坛,但错误仍然出现在同一部分,请帮助 错误部分: bullets.update() ^ 代码:
def update_bullets(bullets):
"""Update position of bullets and gets rid of old bullets"""
#Update bullet position
bullets.update()
# Get rid of bullets that had dissapeared
for bullet in bullets.copy():
if bullet.rect.bottom <= 1:
bullets.remove(bullet)
print(len(bullets))
正确缩进的代码应如下所示:
def update_bullets(bullets):
"""Update position of bullets and gets rid of old bullets"""
#Update bullet position
bullets.update()
# Get rid of bullets that had dissapeared
for bullet in bullets.copy():
if bullet.rect.bottom <= 1:
bullets.remove(bullet)
print(len(bullets))
Python 代码始终需要适当的缩进。空格很重要(与 C 不同)!
我建议查看 this tutorial 以获得有关 Python 的基本教程。