1. <tfoot id='qRf7d'></tfoot>

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

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

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

    3. Python:找到最小的整数

      时间:2023-09-11

        <legend id='ycSGF'><style id='ycSGF'><dir id='ycSGF'><q id='ycSGF'></q></dir></style></legend>
              <bdo id='ycSGF'></bdo><ul id='ycSGF'></ul>
                  <tbody id='ycSGF'></tbody>

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

              • <i id='ycSGF'><tr id='ycSGF'><dt id='ycSGF'><q id='ycSGF'><span id='ycSGF'><b id='ycSGF'><form id='ycSGF'><ins id='ycSGF'></ins><ul id='ycSGF'></ul><sub id='ycSGF'></sub></form><legend id='ycSGF'></legend><bdo id='ycSGF'><pre id='ycSGF'><center id='ycSGF'></center></pre></bdo></b><th id='ycSGF'></th></span></q></dt></tr></i><div id='ycSGF'><tfoot id='ycSGF'></tfoot><dl id='ycSGF'><fieldset id='ycSGF'></fieldset></dl></div>
                <tfoot id='ycSGF'></tfoot>
                本文介绍了Python:找到最小的整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我有以下代码:

                l = ['-1.2', '0.0', '1']
                
                x = 100.0
                for i in l:
                    if i < x:
                        x = i
                print x
                

                代码应该在我的列表中找到最小值 (-1.2),但是当我打印x"时,它发现该值仍然是 100.0我的代码哪里出错了?

                The code should find the lowest value in my list (-1.2) but instead when i print 'x' it finds the value is still 100.0 Where is my code going wrong?

                推荐答案

                要找到一个列表的最小值,你不妨使用 min:

                To find the minimum value of a list, you might just as well use min:

                x = min(float(s) for s in l) # min of a generator
                

                或者,如果您希望将结果作为字符串而不是浮点数,请使用 关键功能:

                Or, if you want the result as a string, rather than a float, use a key function:

                x = min(l, key=float)
                

                这篇关于Python:找到最小的整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何在python中取数字的第n位 下一篇:在 Python 中将字符串转换为带小数的整数

                相关文章

                最新文章

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

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

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

                <tfoot id='kWI6v'></tfoot>