A Python SyntaxError is raised when the Python interpreter runs into code with syntax that is invalid. For example, if code rules such as closing quotes aren’t followed, Python raises a SyntaxError.