封装
import datetime
class Book:
count = 0
#初始化执行
def __init__(self,title,price = 0.0,publisher = '',pubdate = datetime.date.today()):#初始化器,构造函数初始化内成员用的
self.title = title,
self.price = price
self.publisher = publisher
self.pubdate = pubdate
Book.count += 1
#删除对象执行
def __del__(self):
Book.count -= 1
def __repr__(self):
print('<图书{}at{}>'.format(self.title,id(self)))
def __str__(self):
print('[图书{}at{}]'.format(self.title, id(self)))
def print_informance(self):
print('书名:{}'.format(self.title))
print('价格:{}'.format(self.price))
print('出版社:{}'.format(self.publisher