<legend id='WTG8I'><style id='WTG8I'><dir id='WTG8I'><q id='WTG8I'></q></dir></style></legend>

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

    2. <tfoot id='WTG8I'></tfoot>

      1. <small id='WTG8I'></small><noframes id='WTG8I'>

        Python 类 __div__ 问题

        Python Class __div__ issue(Python 类 __div__ 问题)
          <legend id='tnphB'><style id='tnphB'><dir id='tnphB'><q id='tnphB'></q></dir></style></legend>
            <tbody id='tnphB'></tbody>
            <bdo id='tnphB'></bdo><ul id='tnphB'></ul>

                <small id='tnphB'></small><noframes id='tnphB'>

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

                1. <tfoot id='tnphB'></tfoot>
                  本文介绍了Python 类 __div__ 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  元组代表分数.我试图通过乘以倒数来除分数

                  The tuples represent fractions. I'm trying to divide the fractions by multiplying by the reciprical

                  class Test():
                      def __init__(self):
                          self._x=(1,2)
                      def __div__(self,div_fraction):
                          return (self._x[0]*div_fraction[1],self._x[1]*div_fraction[0])
                  
                  y=Test()
                  z=y/(1,3)
                  print(z)
                  

                  给我:

                  Traceback (most recent call last):
                    File "E:/test.py", line 8, in <module>
                     z=y/(1,3)
                  TypeError: unsupported operand type(s) for /: 'Test' and 'tuple'
                  

                  然而,当我将 __div__ 更改为 __mul__ 并使用 * 而不是 / 时,它会做它应该做的事情.

                  Yet when I change the __div__ to __mul__ and use * instead of / it does what it should.

                  如何解决我遇到的异常?

                  How do I fix the exception I'm getting?

                  推荐答案

                  Python 3.x 使用 __truediv____floordiv__.__div__ 仅适用于 2.x.

                  Python 3.x uses __truediv__ and __floordiv__. __div__ is 2.x-only.

                  这篇关于Python 类 __div__ 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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='oeWLE'></tbody>

                  <small id='oeWLE'></small><noframes id='oeWLE'>

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