久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<tfoot id='4RDNG'></tfoot>
<legend id='4RDNG'><style id='4RDNG'><dir id='4RDNG'><q id='4RDNG'></q></dir></style></legend>

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

<small id='4RDNG'></small><noframes id='4RDNG'>

          <bdo id='4RDNG'></bdo><ul id='4RDNG'></ul>
      1. 為什么調用 Python 的“魔術方法"不像對應的運

        Why does calling Python#39;s #39;magic method#39; not do type conversion like it would for the corresponding operator?(為什么調用 Python 的“魔術方法不像對應的運算符那樣進行類型轉換?) - IT屋-程序員軟件開發技
        <tfoot id='xZQOC'></tfoot>
          <i id='xZQOC'><tr id='xZQOC'><dt id='xZQOC'><q id='xZQOC'><span id='xZQOC'><b id='xZQOC'><form id='xZQOC'><ins id='xZQOC'></ins><ul id='xZQOC'></ul><sub id='xZQOC'></sub></form><legend id='xZQOC'></legend><bdo id='xZQOC'><pre id='xZQOC'><center id='xZQOC'></center></pre></bdo></b><th id='xZQOC'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='xZQOC'><tfoot id='xZQOC'></tfoot><dl id='xZQOC'><fieldset id='xZQOC'></fieldset></dl></div>

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

              <tbody id='xZQOC'></tbody>

                  <bdo id='xZQOC'></bdo><ul id='xZQOC'></ul>
                • <legend id='xZQOC'><style id='xZQOC'><dir id='xZQOC'><q id='xZQOC'></q></dir></style></legend>
                  本文介紹了為什么調用 Python 的“魔術方法"不像對應的運算符那樣進行類型轉換?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  當我從整數中減去浮點數時(例如 1-2.0),Python 會進行隱式類型轉換(我認為).但是當我使用魔術方法 __sub__ 調用我認為是相同的操作時,它突然不再存在了.

                  When I subtract a float from an integer (e.g. 1-2.0), Python does implicit type conversion (I think). But when I call what I thought was the same operation using the magic method __sub__, it suddenly does not anymore.

                  我在這里缺少什么?當我為自己的類重載運算符時,除了將輸入顯式轉換為我需要的任何類型之外,還有其他方法嗎?

                  What am I missing here? When I overload operators for my own classes, is there a way around this other than explicitly casting input to whatever type I need?

                  a=1
                  a.__sub__(2.)
                  # returns NotImplemented
                  a.__rsub__(2.)
                  # returns NotImplemented
                  # yet, of course:
                  a-2.
                  # returns -1.0
                  

                  推薦答案

                  a - b 不僅僅是 a.__sub__(b).如果 a 無法處理該操作,它也會嘗試 b.__rsub__(a),在 1 - 2. 的情況下,它是float 的 __rsub__ 處理操作.

                  a - b isn't just a.__sub__(b). It also tries b.__rsub__(a) if a can't handle the operation, and in the 1 - 2. case, it's the float's __rsub__ that handles the operation.

                  >>> (2.).__rsub__(1)
                  -1.0
                  

                  您運行了 a.__rsub__(2.),但這是錯誤的 __rsub__.您需要右側操作數的 __rsub__,而不是左側操作數.

                  You ran a.__rsub__(2.), but that's the wrong __rsub__. You need the right-side operand's __rsub__, not the left-side operand.

                  減法運算符沒有內置隱式類型轉換.float.__rsub__ 必須手動處理整數.如果您想在自己的運算符實現中進行類型轉換,您也必須手動處理.

                  There is no implicit type conversion built into the subtraction operator. float.__rsub__ has to handle ints manually. If you want type conversion in your own operator implementations, you'll have to handle that manually too.

                  這篇關于為什么調用 Python 的“魔術方法"不像對應的運算符那樣進行類型轉換?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How to bind a function to an Action from Qt menubar?(如何將函數綁定到 Qt 菜單欄中的操作?)
                  PyQt progress jumps to 100% after it starts(PyQt 啟動后進度躍升至 100%)
                  How to set yaxis tick label in a fixed position so that when i scroll left or right the yaxis tick label should be visible?(如何將 yaxis 刻度標簽設置在固定位置,以便當我向左或向右滾動時,yaxis 刻度標簽應該可見
                  `QImage` constructor has unknown keyword `data`(`QImage` 構造函數有未知關鍵字 `data`)
                  Change x-axis ticks to custom strings(將 x 軸刻度更改為自定義字符串)
                  How to show progress bar while saving file to excel in python?(如何在python中將文件保存為excel時顯示進度條?)

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

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

                        <tfoot id='WlciZ'></tfoot>

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

                            主站蜘蛛池模板: 国产96色在线 | 亚洲自拍一区在线观看 | 北条麻妃视频在线观看 | 亚洲 欧美 另类 日韩 | 日本a视频 | 欧美视频成人 | 欧美一级黄色片免费观看 | 欧州一区二区 | 九九热精品在线 | 91精品国产一区二区三区蜜臀 | 久久99国产精一区二区三区 | 亚洲综合久久精品 | 国内自拍第一页 | 国产激情视频网 | 亚洲国产精品99久久久久久久久 | 久久国产精品久久 | 久久99精品久久久久久 | 精品一区二区视频 | 久久久久国产一区二区 | 国产精品96久久久久久 | 自拍视频国产 | 网黄在线| 亚洲国产精品久久久久久 | 国产精品精品久久久 | 亚洲国产精品一区二区三区 | 日韩插插| 一级中国毛片 | 精品视频久久久 | 日日夜夜av| 国产黄色在线观看 | 狠狠躁18三区二区一区 | 欧美精品久久久久久久久老牛影院 | 91精品国产乱码久久久 | 欧美一级欧美一级在线播放 | 久久久久久国产精品免费免费 | 999国产视频 | 欧美在线一区视频 | 亚洲一区二区三区在线观看免费 | 伊人国产精品 | 国产在线1 | 国产精品日韩欧美一区二区三区 |