'''
知识点:
1.has a
一个类中使用了另外一种自定义类的类型
student 使用computer book
2.类型
系统类型
str,int,float,list,tuple,dic,set
自定义类型
算是自定义的类,都可以将其当成一种类型
student是一种类型
s=Student()
s是Student的类型
class Student:#has adef __init__(self,name,age,computer,book):self.name=nameself.age=ageself.computer=computerself.books=[]self.books.append(book)def __str__(self):return(f"{self.name}今年 {self.age}岁,他有一本{str(self.computer)},借了{[book.bname for book in self.books]}")def borrow_book(self,book1):for book in self.books:if book1.bname == book.bname:print(f'{book.bname}这本书已经借过啦,不可以借了')breakelse:self.books.append(book1)print('添加成功!')print('{}借了{}'.format(self.name,[book.bname for book in self.books]))def show_books(self):for book in self.books:#book就是book对象print(book.bname)class Book:def __init__(self,bname,author,number):self.bname=bnameself.author=authorself.number=numberdef __str__(self):return('{}这本书的作者是{},有{}本'.format(self.bname,self.author,self.number))class Computer:def __init__(self,brand,type,color):self.brand=brandself.type=typeself.color=colordef online(self):print('正在使用电脑{}上网'.format(self.brand))def __str__(self):return('电脑的品牌是:'+str(self.brand)+self.type)
c1=Computer('Dell','2020','red')
b1=Book('python','李凯','5')
b2=Book('鬼吹灯','天下霸唱','10')
print(b1)
print(b2)
s1=Student('kate',24,c1,b1)
print(s1)
s1.borrow_book(b2)
print('----------------------------')
s1.show_books()