Changes

Jump to: navigation, search

OPS435 Python3 Lab 7

4 bytes added, 12:54, 4 November 2019
Part 2 - Special object methods
def __str__(self):
'''return a string representation for the object self'''
return '%.2d:%.2d:%.2d' % (self.hour, self.minute, self.second)
</source>
:1. Make a copy of lab7d.py and name it as lab7e.py. Add the function definition for __str__() after the __init__() function in lab7e.py. Make sure that the '''def __str__(self):''' line has the same indentation level as the __init__() function.
def __repr__(self):
'''return a string representation for the object self'''
return '%.2d.%.2d.%.2d' % (self.hour, self.minute, self.second)
</source>
:6. Add the function definition for __repr__() after the __str__() function in lab7e.py. Please note that we use the '.' instead of ':' in the formatting string. Make sure that the '''def __repr__(self):''' line has the same indentation level as the __init__() function.
1,760
edits

Navigation menu