封装,顾名思义就是将内容封装到某个地方,以后再去调用被封装在某处的内容。
所以,在使用面向对象的封装特性时,需要:
class Person:
Ethnicity = 'human'
def __init__(self, name, age):
self.name = name
self.age = age
def study(self, book):
print('%s is studying %s' % (self.name, book))
jack = Person('jack', 18)
print('%s is %s years.' % (jack.name, jack.age))
jack.study('python')