87-OOP之必需掌握的magic
作者:
凯茜的老爸 | 来源:发表于
2018-08-02 16:03 被阅读3次class Book:
def __init__(self, title, author, pages):
self.title = title
self.author = author
self.pages = pages
def __str__(self):
return '《%s》' % self.title
def __call__(self):
print('《%s》is written by %s' % (self.title, self.author))
if __name__ == '__main__':
py_book = Book('Core Python', 'Wesley', 800) # 调用__init__()方法
print(py_book) # 调用__str__
py_book() # 调用__call__
本文标题:87-OOP之必需掌握的magic
本文链接:https://www.haomeiwen.com/subject/wohsvftx.html
网友评论