2017-04-07 16 views
-7

我有錯誤,說「IndentationError:unindent不匹配任何外部縮進級別」,我已嘗試使用命令並更改空間和選項卡,但仍然錯誤繼續出現,並且我已嘗試所有我已經閱讀論壇上,但仍出現在同一部位錯誤,請幫忙 誤差部分: bullets.update() ^ 代碼:Identation Error

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)) 
+5

python中的縮進將在任何教程中介紹。 – Julien

+1

在Python中,空白是相關的。你的縮進遍佈整個地方,而這絕不會奏效。您可以在http://python.org找到Python教程 –

+2

縮進的作用幾乎肯定是任何Python教科書或教程中的第一課。如何在不知情的情況下學習語言? – Barmar

回答

2

您的代碼,進行適當的縮進,應該是這樣的:

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基本教程。

+1

@KenWhite不夠公平,我詳細闡述了我的答案。 –