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

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

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

        Python,确定字符串是否应转换为 Int 或 Float

        时间:2023-08-04

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

          <tbody id='oTfw5'></tbody>

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

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

              • <tfoot id='oTfw5'></tfoot>
                  本文介绍了Python,确定字符串是否应转换为 Int 或 Float的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想将字符串转换为最紧凑的数据类型:int 或 float.

                  I want to convert a string to the tightest possible datatype: int or float.

                  我有两个字符串:

                  value1="0.80"     #this needs to be a float
                  value2="1.00"     #this needs to be an integer.
                  

                  如何确定在 Python 中 value1 应该是 Float 而 value2 应该是 Integer?

                  How I can determine that value1 should be Float and value2 should be Integer in Python?

                  推荐答案

                  def isfloat(x):
                      try:
                          a = float(x)
                      except (TypeError, ValueError):
                          return False
                      else:
                          return True
                  
                  def isint(x):
                      try:
                          a = float(x)
                          b = int(a)
                      except (TypeError, ValueError):
                          return False
                      else:
                          return a == b
                  

                  这篇关于Python,确定字符串是否应转换为 Int 或 Float的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:使用 Pandas 将整个数据帧从小写转换为大写 下一篇:列表列表,将所有字符串转换为 int,Python 3

                  相关文章

                  最新文章

                  <legend id='p6fxO'><style id='p6fxO'><dir id='p6fxO'><q id='p6fxO'></q></dir></style></legend>
                  <tfoot id='p6fxO'></tfoot>

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

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

                      • <bdo id='p6fxO'></bdo><ul id='p6fxO'></ul>