一个牛角尖问题吗,求大牛解答,祝大神中秋快乐
不多说上代码
===================第一个代码============
class Book:
def __init__(self, name, author, comment, state = 0):
self.name = name
self.author = author
self.comment = comment
self.state = state
# 创建一个Book类的子类 FictonBook
class FictonBook(Book):
def __init__(self, name, author, comment, state = 0, type = '虚构类'):
Book.__init__(self, name, author, comment, state = 0)-------------------这行不明白这里为什么有self
self.type = type
=========第二个代码=====================
class BookManager
def menu(self):
print('欢迎使用流浪图书管理系统\n')
while True:
print('1.查询所有书籍\n2.添加书籍\n3.借阅书籍\n4.归还书籍\n5.退出系统\n')
choice = int(input('请输入数字选择对应的功能:'))
if choice == 1:
self.show_all_book()-----------------------------------这行不明白 这里为什么没有self
def show_all_book(self):
print('书籍信息如下:')
for book in self.books:
print(book)
print('')
======================================
问题就是蓝色文字,第一个代码 和 第二个代码的区别就是 第一个是跨类调用函数 第二个是自调用函数 这是我能想到的区别了,但仍旧没搞明白self有时写 有时又不写 求大神解答呀 :)