sissivic 发表于 2020-7-3 14:17:16

求debug简单的类 说name 'Student' is not defined?

class Student():
    name = ''
    age = 0

    def print_file(self):
      print("name:" + self.name)
      print("age:" + str(self.age))


    student = Student()
    student.print_file()

永恒的蓝色梦想 发表于 2020-7-3 14:21:25

class Student():
    name = ''
    age = 0

    def print_file(self):
      print("name:" + self.name)
      print("age:" + str(self.age))


student = Student()
student.print_file()

青出于蓝 发表于 2020-7-3 14:27:36

age是整形不是字符串,需要str变成字符串
2楼正解

sissivic 发表于 2020-7-3 15:25:52

青出于蓝 发表于 2020-7-3 14:27
age是整形不是字符串,需要str变成字符串
2楼正解

对的谢谢 而且
student = Student()
student.print_file()
这些类方法调用/使用 放到外面一个模块去~我 的缩进=。=
页: [1]
查看完整版本: 求debug简单的类 说name 'Student' is not defined?