The library requires a class to store information about a book. Set up a class to hold data including title, author, year of publication, and a boolean variable to indicate if the book is in the libr
时间: 2023-07-02 22:10:45 浏览: 50
ary or not. Here is an example implementation in Python:
```python
class Book:
def __init__(self, title, author, year, in_library):
self.title = title
self.author = author
self.year = year
self.in_library = in_library
```
This class has an `__init__` method that takes four arguments: `title`, `author`, `year`, and `in_library`. These correspond to the data we want to store about the book. `title`, `author`, and `year` are all string or numeric values, while `in_library` is a boolean value that indicates whether the book is in the library or not.
Once a `Book` object is created, its attributes can be accessed using dot notation. For example:
```python
book1 = Book("The Hunger Games", "Suzanne Collins", 2008, True)
print(book1.title) # prints "The Hunger Games"
print(book1.in_library) # prints True
book2 = Book("To Kill a Mockingbird", "Harper Lee", 1960, False)
print(book2.author) # prints "Harper Lee"
print(book2.in_library) # prints False
```