• <bdo id='SKH93'></bdo><ul id='SKH93'></ul>
      <tfoot id='SKH93'></tfoot>

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

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

        如何测试“int"类型列表中的每个项目是否?

        时间:2023-09-11
        <legend id='fdvk3'><style id='fdvk3'><dir id='fdvk3'><q id='fdvk3'></q></dir></style></legend>
        • <i id='fdvk3'><tr id='fdvk3'><dt id='fdvk3'><q id='fdvk3'><span id='fdvk3'><b id='fdvk3'><form id='fdvk3'><ins id='fdvk3'></ins><ul id='fdvk3'></ul><sub id='fdvk3'></sub></form><legend id='fdvk3'></legend><bdo id='fdvk3'><pre id='fdvk3'><center id='fdvk3'></center></pre></bdo></b><th id='fdvk3'></th></span></q></dt></tr></i><div id='fdvk3'><tfoot id='fdvk3'></tfoot><dl id='fdvk3'><fieldset id='fdvk3'></fieldset></dl></div>

          <tfoot id='fdvk3'></tfoot>

                  <bdo id='fdvk3'></bdo><ul id='fdvk3'></ul>
                    <tbody id='fdvk3'></tbody>

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

                  本文介绍了如何测试“int"类型列表中的每个项目是否?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  假设我有一个数字列表.我将如何检查列表中的每个项目都是 int?
                  我四处搜寻,但找不到任何关于此的东西.

                  Say I have a list of numbers. How would I do to check that every item in the list is an int?
                  I have searched around, but haven't been able to find anything on this.

                  for i in myList:
                    result=isinstance(i, int)
                    if result == False:
                      break
                  

                  会起作用,但在我看来,它看起来很丑陋且不符合标准.
                  有没有更好(和更pythonic)的方法来做到这一点?

                  would work, but looks very ugly and unpythonic in my opinion.
                  Is there any better(and more pythonic) way of doing this?

                  推荐答案

                  >>> my_list = [1, 2, 3.25]
                  >>> all(isinstance(item, int) for item in my_list)
                  False
                  
                  >>> other_list = range(3)
                  >>> all(isinstance(item, int) for item in other_list)
                  True
                  >>> 
                  

                  这篇关于如何测试“int"类型列表中的每个项目是否?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何将字典中的字符串值转换为 int/float 数据类型 下一篇:在 Pandas DataFrame 中转换列值的最有效方法

                  相关文章

                  最新文章

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

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

                    <bdo id='ju3YS'></bdo><ul id='ju3YS'></ul>
                    1. <legend id='ju3YS'><style id='ju3YS'><dir id='ju3YS'><q id='ju3YS'></q></dir></style></legend>