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

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

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

      1. Python 的 coerce() 是做什么用的?

        时间:2023-09-14

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

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

              <tfoot id='Ga9Mj'></tfoot>
              • <bdo id='Ga9Mj'></bdo><ul id='Ga9Mj'></ul>
                1. <legend id='Ga9Mj'><style id='Ga9Mj'><dir id='Ga9Mj'><q id='Ga9Mj'></q></dir></style></legend>
                  本文介绍了Python 的 coerce() 是做什么用的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  Python 内置的 coerce 函数有哪些常见用途?如果我不知道数值 type ,我可以看到应用它"noreferrer">根据文档,但是否存在其他常见用法?我猜想在执行算术计算时也会调用 coerce()例如 x = 1.0 +2.它是一个内置函数,所以大概它有一些潜在的常见用法?

                  What are common uses for Python's built-in coerce function? I can see applying it if I do not know the type of a numeric value as per the documentation, but do other common usages exist? I would guess that coerce() is also called when performing arithmetic computations, e.g. x = 1.0 +2. It's a built-in function, so presumably it has some potential common usage?

                  推荐答案

                  它是 早期的python,它基本上使一个数字元组成为相同的底层数字类型,例如

                  Its a left over from early python, it basically makes a tuple of numbers to be the same underlying number type e.g.

                  >>> type(10)
                  <type 'int'>
                  >>> type(10.0101010)
                  <type 'float'>
                  >>> nums = coerce(10, 10.001010)
                  >>> type(nums[0])
                  <type 'float'>
                  >>> type(nums[1])
                  <type 'float'>
                  

                  这也是为了让对象在旧类中表现得像数字
                  (在这里使用它的一个不好的例子是......)

                  It is also to allow objects to act like numbers with old classes
                  (a bad example of its usage here would be ...)

                  >>> class bad:
                  ...     """ Dont do this, even if coerce was a good idea this simply
                  ...         makes itself int ignoring type of other ! """
                  ...     def __init__(self, s):
                  ...             self.s = s
                  ...     def __coerce__(self, other):
                  ...             return (other, int(self.s))
                  ... 
                  >>> coerce(10, bad("102"))
                  (102, 10)
                  

                  这篇关于Python 的 coerce() 是做什么用的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:阻止 Pandas 将 int 转换为 float 下一篇:如何将 Numpy 数组转换为 Panda DataFrame

                  相关文章

                  最新文章

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

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

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

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

                      <tfoot id='Ds69n'></tfoot>