Last active
March 18, 2019 22:12
-
-
Save yeaske/2bff666c8bf07588dd821f8084e5c881 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Book: | |
title = None | |
author = None | |
year = None | |
def __init__(self, author, title, year): | |
self.author = author | |
self.title = title | |
self.year = year | |
# Equality check implementation | |
def __eq__(self, other): | |
return self.author == other.author and \ | |
self.title == other.title and \ | |
self.year == other.year | |
# Hash implementation | |
def __hash__(self): | |
return hash(('author', self.author, | |
'title', self.title, | |
'year', self.year)) | |
def __str__(self): | |
return f"{self.title} by {self.author} in {self.year}" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment