python部分函数的后置写法问题

it2022-05-05  118

这种写法原来是因为 类和实例的数据封装。

class Student(object): def __init__(self, name, score): self.name = name self.score = score def print_score(self): print('%s: %s' % (self.name, self.score)) bart = Student('Bart Simpson', 59) bart.print_score(self)

bart.print_score(self) 的写法即为数据封装,此外

class Student(object): def __init__(self, name, score): self.n = name self.s = score

self.n,self.f 这两个属性,完全是和self对应的,其后面的参数对应传入参数


最新回复(0)