python实现输出图书管理系统里的所有信息代码
时间: 2024-11-12 07:44:23 浏览: 3
在Python中,实现一个简单的图书管理系统并输出所有信息,可以使用面向对象的方式,创建一个图书类Book以及一个图书馆类Library。下面是一个简化的示例:
```python
class Book:
def __init__(self, id, title, author, publication_date):
self.id = id
self.title = title
self.author = author
self.publication_date = publication_date
class Library:
def __init__(self):
self.books = []
def add_book(self, book):
self.books.append(book)
def display_books(self):
for book in self.books:
print(f"ID: {book.id}, Title: {book.title}, Author: {book.author}, Publication Date: {book.publication_date}")
# 创建书籍实例并添加到图书馆
library = Library()
library.add_book(Book(1, "Python Crash Course", "Eric Matthes", "2015"))
library.add_book(Book(2, "Clean Code", "Robert C. Martin", "2008"))
# 输出所有书籍信息
library.display_books()
阅读全文