gpt4 book ai didi

python - python 中的 `and` 和 `or` 是否存在 Dunder 方法(魔术方法)?

转载 作者:行者123 更新时间:2023-12-04 14:43:39 24 4
gpt4 key购买 nike

__and____or__&|分别是 and 是否有可修改的 dunders和 or也?
如果是这样,我似乎无法找到它们。它们未列在此处的文档中:
https://docs.python.org/3/reference/datamodel.html
上下文:在我希望人们能够做的地方制作 api foo and bar and jar , 而不是必须做 method(method(foo, bar),jar) .我仍然可以使用 &|但只是好奇,更喜欢 and 的可读性和 or

最佳答案

PEP 335 -- Overloadable Boolean Operators 2012年被拒,rejection notice :

We've had many discussions in the past about PEP 335 and they alwaysended in non-action. I'm cutting any future discussions short andofficially rejecting the PEP. Amongst other reasons, I really dislikethat the PEP adds to the bytecode for all uses of these operators eventhough almost no call sites will ever need the feature.

关于python - python 中的 `and` 和 `or` 是否存在 Dunder 方法(魔术方法)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68899454/

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