您在這裡

A more complicated example

8 九月, 2015 - 10:52

is_after (from Exercise 16.2 in Time) is slightly more complicated because it takes two Time objects as parameters. In this case it is conventional to name the first parameter self and the second parameter other:

# inside class Time:
 
def is_after(self, other):
return self.time_to_int() > other.time_to_int()

To use this method, you have to invoke it on one object and pass the other as an argument:

>>> end.is_after(start)True

One nice thing about this syntax is that it almost reads like English: “end is after start?”