Python调用类语法错误

时间:2017-03-11 08:21:53

标签: python class syntax-error

为什么此代码有语法错误而不能运行?

class AboutMe :
    def __init__(self, myname, myschool, myage):
        self.name = myname
        self.school = myschool
        self.age = myage

    def myName(self):
        return self.name

    def mySchool(self):
        return self.school

    def myAge(self):
        return self.age

myname=input('Enter your name: ')
myschool=input('Enter your school: ')
myage=int(input('Enter your age: ')

a=AboutMe(myname,myschool,myage) #syntax error in this line

print('\nHello!')
print('My name is %s, and I attend %s. I am %d years old.'
      %(a.myName(),a.mySchool(),a.myAge()))

1 个答案:

答案 0 :(得分:0)

myage=int(input('Enter your age: ')在最后再遗失一个),因此下一行会导致错误。