Skip to content

Instantly share code, notes, and snippets.

@yeaske
Last active March 18, 2019 22:12
Show Gist options
  • Save yeaske/2bff666c8bf07588dd821f8084e5c881 to your computer and use it in GitHub Desktop.
Save yeaske/2bff666c8bf07588dd821f8084e5c881 to your computer and use it in GitHub Desktop.
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