我正在尝试创建一个类,但会弹出此错误

时间:2019-10-28 06:59:14

标签: python

我只是从本书的python崩溃课程中学习,而当我在class部分时,我创建了一个类,但是当我尝试运行它时,我的IDE(Pycharm)在def__init __(self,name,age)中说无效的语法错误:

def__init__(self,  name, age):
                             ^
SyntaxError: invalid syntax

Process finished with exit code 1

class Dog():
"""A simple attempt to model a Dog"""

def__init(self, name, age):
    """Initialize name and age attributes"""
    self.name = name
    self.age = age


def sit(self):
    """Simulate a dog sitting in response to  command"""
    print(self.name.title() + "is now sitting.")

code image error image图片] 2

0 个答案:

没有答案