Discuss / Python / 为什么 print(bart.score_1()) 会出现none

为什么 print(bart.score_1()) 会出现none

Topic source

class Student(object): def init(self, name, score): self.name = name self.score = score def score_1(self): print("%s: %s" % (self.name, self.score))

bart = Student('zhang', 99) print(bart.score_1())

结果:

zhang: 99 None

MaRtiNe11

#2 Created at ... [Delete] [Delete and Lock User]

函数没有返回值时,自动返回None

score_1()这个函数没有返回值,你函数里面就输出了,直接执行bart.score_1()就可以了吧,用不着再弄一个print


  • 1

Reply