Skip to content

Python

语法

  • 类的 __init__() 方法会返回 None 并且只能返回 None
  • with CLASS() [as VAR]: 这个语法中 VAR 会被定义,当离开 with 之后也会存在,类型为 CLASS;进入 with 会调用 CLASS.__enter__(),离开会调用 CLASS.__EXIT__()
  • print(CLASS) 时, __str__() 的优先级会比 __repr__() 高。