Python 缩进错误,但它';It’不要混淆标签和空格

Python 缩进错误,但它';It’不要混淆标签和空格,python,Python,当我尝试运行脚本时,它坚持在第10行definit(self):行上存在缩进错误。查找它时,我尝试了一些常见的修复方法,检查以确保选项卡和空格没有混淆,确保循环结构正确,但没有任何效果 import sys import pygame from settings import Settings from ship import Ship class AlienInvasion: """Overall game assets and behavior"

当我尝试运行脚本时,它坚持在第10行definit(self):行上存在缩进错误。查找它时,我尝试了一些常见的修复方法,检查以确保选项卡和空格没有混淆,确保循环结构正确,但没有任何效果

import sys
import pygame

from settings import Settings
from ship import Ship

class AlienInvasion:
  """Overall game assets and behavior"""
    
    def __init__(self):
        """Initialize the game, and create game resources"""
        pygame.init()
        
        self.settings = Settings()pi
        self.screen = pygame.display.set_mode((self.settings.screen_width, self.settings.screen_height))

        pygame.display.set_caption("Alien Invasion")

        self.ship = Ship(self)

        # Set the background
        self.bg_color = (230, 230, 230)

    def run_game(self):
        """Start the main loop for the game"""
        while True:
            # Watch for keyboard and mouse events.
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    sys.exit()

                # Redraw the screen during each pass through the pass
                self.screen.fill(self.settings.bg_color)
                self.ship.blitme()

            # Make the most recently drawn screen visible
            pygame.display.flip()

if __name__ == '__main__':
    # Make a game instance, and run the game
    ai = AlienInvasion()
    ai.run_game()
如果有人能告诉我发生了什么,我将不胜感激。在我的编程生涯中这么晚才尝试Python是一件很糟糕的事情。

这是:

class AlienInvasion:
  """Overall game assets and behavior"""
应该是这样的:

class AlienInvasion:
    """Overall game assets and behavior"""
以便与下一个定义匹配:

    def __init__(self):

哦,哇。我真的不习惯编写对间距如此敏感的代码,我不知道文档行也必须对齐,因为它们类似于注释,所以在编译时会被忽略。展示我所知道的!谢谢你的帮助@不客气!请注意,文档行实际上是代码(字符串文字),而不是注释!这就是它们需要正确对齐的原因。