• <small id='maMH4'></small><noframes id='maMH4'>

    <tfoot id='maMH4'></tfoot>
    1. <i id='maMH4'><tr id='maMH4'><dt id='maMH4'><q id='maMH4'><span id='maMH4'><b id='maMH4'><form id='maMH4'><ins id='maMH4'></ins><ul id='maMH4'></ul><sub id='maMH4'></sub></form><legend id='maMH4'></legend><bdo id='maMH4'><pre id='maMH4'><center id='maMH4'></center></pre></bdo></b><th id='maMH4'></th></span></q></dt></tr></i><div id='maMH4'><tfoot id='maMH4'></tfoot><dl id='maMH4'><fieldset id='maMH4'></fieldset></dl></div>
        <bdo id='maMH4'></bdo><ul id='maMH4'></ul>
    2. <legend id='maMH4'><style id='maMH4'><dir id='maMH4'><q id='maMH4'></q></dir></style></legend>

        是否应将__ne__实现为__eq__的否定?

        Should __ne__ be implemented as the negation of __eq__?(是否应将__ne__实现为__eq__的否定?)
        <tfoot id='iY98h'></tfoot>

            • <legend id='iY98h'><style id='iY98h'><dir id='iY98h'><q id='iY98h'></q></dir></style></legend>
            • <small id='iY98h'></small><noframes id='iY98h'>

                  <tbody id='iY98h'></tbody>

                • <bdo id='iY98h'></bdo><ul id='iY98h'></ul>
                  <i id='iY98h'><tr id='iY98h'><dt id='iY98h'><q id='iY98h'><span id='iY98h'><b id='iY98h'><form id='iY98h'><ins id='iY98h'></ins><ul id='iY98h'></ul><sub id='iY98h'></sub></form><legend id='iY98h'></legend><bdo id='iY98h'><pre id='iY98h'><center id='iY98h'></center></pre></bdo></b><th id='iY98h'></th></span></q></dt></tr></i><div id='iY98h'><tfoot id='iY98h'></tfoot><dl id='iY98h'><fieldset id='iY98h'></fieldset></dl></div>

                  本文介绍了是否应将__ne__实现为__eq__的否定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个要覆盖__eq__方法的类。似乎我也应该覆盖__ne__方法。我应该将__ne__实现为__eq__的否定,还是这样做不好?

                  class A:
                  
                      def __init__(self, state):
                          self.state = state
                  
                      def __eq__(self, other):
                          return self.state == other.state
                  
                      def __ne__(self, other):
                          return not self.__eq__(other)
                  

                  推荐答案

                  可以,非常好。实际上,the documentation会提示您在定义__eq__时定义__ne__

                  没有隐含关系 在比较运算符中。这个 x==y的真实性并不意味着x!=y 是假的。因此,在定义 __eq__(),还应定义__ne__(),以便运算符的行为符合预期。

                  在许多情况下(如本例),只需否定__eq__的结果,但并不总是如此。

                  这篇关于是否应将__ne__实现为__eq__的否定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
                  Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
                  Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
                  Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
                  Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)
                  Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)
                    <tbody id='JvwNw'></tbody>
                    1. <i id='JvwNw'><tr id='JvwNw'><dt id='JvwNw'><q id='JvwNw'><span id='JvwNw'><b id='JvwNw'><form id='JvwNw'><ins id='JvwNw'></ins><ul id='JvwNw'></ul><sub id='JvwNw'></sub></form><legend id='JvwNw'></legend><bdo id='JvwNw'><pre id='JvwNw'><center id='JvwNw'></center></pre></bdo></b><th id='JvwNw'></th></span></q></dt></tr></i><div id='JvwNw'><tfoot id='JvwNw'></tfoot><dl id='JvwNw'><fieldset id='JvwNw'></fieldset></dl></div>

                        • <small id='JvwNw'></small><noframes id='JvwNw'>

                            <bdo id='JvwNw'></bdo><ul id='JvwNw'></ul>

                            <legend id='JvwNw'><style id='JvwNw'><dir id='JvwNw'><q id='JvwNw'></q></dir></style></legend>
                          • <tfoot id='JvwNw'></tfoot>