""" person.py Jed Yang, 2017-03-31 toString and equality testing. Intended as the Python half of parallel examples in Python and Java. See Person.java. """ class Person: def __init__(self, first, last): """Sets first and last names.""" self.first = first self.last = last def __str__(self): """Returns full name when a string version is requested.""" return self.first + " " + self.last def __eq__(self, other): """Two Person objects are equal if and only if their 'last' are equal.""" return self.last == other.last jed = Person('Jed', 'Yang') print(jed) # Note that print() seems to automagically call __str__ method. # Try commenting out __str__ method above to see what would happen. lindsay = Person('Lindsay', 'Yang') print(jed == lindsay) # Note that == automagically runs __eq__ method. # Try commenting out __eq__ method above to see what would happen.