使用的返回值
__iadd__()。您无需返回要添加到的对象;您可以创建一个新的并将其返回。实际上,如果对象是不可变的,则必须 这样 做。
import os.pathclass Path(str): def __iadd__(self, other): return Path(os.path.join(str(self), str(other)))path = Path("C:\")path += "windows"print path
使用的返回值
__iadd__()。您无需返回要添加到的对象;您可以创建一个新的并将其返回。实际上,如果对象是不可变的,则必须 这样 做。
import os.pathclass Path(str): def __iadd__(self, other): return Path(os.path.join(str(self), str(other)))path = Path("C:\")path += "windows"print path