• <bdo id='hif3P'></bdo><ul id='hif3P'></ul>
  • <small id='hif3P'></small><noframes id='hif3P'>

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

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

        在 Python 中使用 try/except 将字符串转换为 Int

        Converting String to Int using try/except in Python(在 Python 中使用 try/except 将字符串转换为 Int)

      1. <tfoot id='npAm9'></tfoot>
          <tbody id='npAm9'></tbody>

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

          • <legend id='npAm9'><style id='npAm9'><dir id='npAm9'><q id='npAm9'></q></dir></style></legend>

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

                  本文介绍了在 Python 中使用 try/except 将字符串转换为 Int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  所以我很困惑如何使用 try/except 函数将字符串转换为 int.有谁知道如何做到这一点的简单功能?我觉得我在字符串和整数上仍然有点朦胧.我非常有信心整数与数字有关.字符串...不是那么多.

                  So I'm pretty stumped on how to convert a string into an int using the try/except function. Does anyone know a simple function on how to do this? I feel like I'm still a little hazy on string and ints. I'm pretty confident that ints are related to numbers. Strings...not so much.

                  推荐答案

                  在使用 try/except 块时,具体说明您要捕获的异常非常重要.

                  It is important to be specific about what exception you're trying to catch when using a try/except block.

                  string = "abcd"
                  try:
                      string_int = int(string)
                      print(string_int)
                  except ValueError:
                      # Handle the exception
                      print('Please enter an integer')
                  

                  Try/Excepts 非常强大,因为如果某事可能以多种不同的方式失败,您可以指定您希望程序在每种失败情况下如何反应.

                  Try/Excepts are powerful because if something can fail in a number of different ways, you can specify how you want the program to react in each fail case.

                  这篇关于在 Python 中使用 try/except 将字符串转换为 Int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Split a Pandas column of lists into multiple columns(将 Pandas 的列表列拆分为多列)
                  How does the @property decorator work in Python?(@property 装饰器在 Python 中是如何工作的?)
                  What is the difference between old style and new style classes in Python?(Python中的旧样式类和新样式类有什么区别?)
                  How to break out of multiple loops?(如何打破多个循环?)
                  How to put the legend out of the plot(如何将传说从情节中剔除)
                  Why is the output of my function printing out quot;Nonequot;?(为什么我的函数输出打印出“无?)

                      <tfoot id='DMsbh'></tfoot>
                        <tbody id='DMsbh'></tbody>
                        <bdo id='DMsbh'></bdo><ul id='DMsbh'></ul>

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

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