[Python] 碎片 - 类
例: Fraction 类 重写 __init__ 方法 要创建一个 Fraction 对象,需要提供分子和分母两部分数据。在 Python 中,构造方法总是命名为 __init__ (即在 init 的前后分别有两个下划线) Fraction 类及其构造方法: class Fraction: def __init__(self, top, bottom): s
例: Fraction 类 重写 __init__ 方法 要创建一个 Fraction 对象,需要提供分子和分母两部分数据。在 Python 中,构造方法总是命名为 __init__ (即在 init 的前后分别有两个下划线) Fraction 类及其构造方法: class Fraction: def __init__(self, top, bottom): s