gpt4 book ai didi

python - 在 Python 中覆盖 "+="? (__iadd__() 方法)

转载 作者:IT老高 更新时间:2023-10-28 20:22:00 24 4
gpt4 key购买 nike

是否可以在 Python 中覆盖 +=?

最佳答案

是的,覆盖 __iadd__方法。示例:

def __iadd__(self, other):
self.number += other.number
return self

关于python - 在 Python 中覆盖 "+="? (__iadd__() 方法),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1047021/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com