摘要:
一,运算符重载 如果通过定义一些特定的方法,就能针对自定义类型,让运算符有特定的作用。 比如,如果你在 Time 类中定义了一个名为add的方法,你就可以对 Time 对象使用 + 加号运算符。 >>> class Time: ... def __init__(self, hour=0, minut 阅读全文
摘要:
写一些函数,这些函数用自定义类型做参数和返回值。 一,时间 定义一个叫做 Time 的类,记录下当日的时间: >>> class Time: ... """Represents the time of day. ... attributes: hour, minute, second.""" ... 阅读全文