Skip to main content
Engineering LibreTexts

17.4: A more complicated example

  • Page ID
    40832
  • Rewriting is_after (from Section 16.1) 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?”

    • Was this article helpful?