Changes

Jump to: navigation, search

Rchan sandbox

50 bytes added, 09:19, 3 November 2019
Part 1 - Classes and Methods
In the previous investigation, the functions that were defined for manipulating our time object are not tied directly to our time object. Given our time object alone, we won't be able to tell that there exist a function called sum_times() which can be used to add two time objects and return their sum.
To tie up those functions to our time objects, we only need to move those functions definition under the class block which define our Time object.
== Part 1 - Classes and Methods for our Time objects ==The following illustration show shows how to we can change external functions to become object methods (aka class functions)for our Time object. It is simply by moving the function definition definitions to be under the class definition for the new type of Time object:
<source lang="python">
#!/usr/bin/env python3
return time
</source>
Please notice that the function named sec_to_time() did not get moved. It remains as an external function.
:1. Create a new file and name it as '''lab7d.py''' and place the code above in it.
1,760
edits

Navigation menu