封装:
封装前先·
class student(object):
def __init__(self,name,score):
self.name=name
self.score=score
std=student('sisi',9)
def info(std):
print('student:%s,score:%s'%(std.name,std.score))
info(std)
封装后
class student1(object):
def __init__(self,name,score):
self.name=name
self.score=score
def info(self):
print('student:%s,score:%s'%(self.name,self.score))
st=student1('xixi',10)
info(st)
效果:
数据和逻辑封装了,直接调用,不用知道内部细节。