1. <small id='87VJ3'></small><noframes id='87VJ3'>

      <tfoot id='87VJ3'></tfoot>

      <legend id='87VJ3'><style id='87VJ3'><dir id='87VJ3'><q id='87VJ3'></q></dir></style></legend>

        • <bdo id='87VJ3'></bdo><ul id='87VJ3'></ul>
        <i id='87VJ3'><tr id='87VJ3'><dt id='87VJ3'><q id='87VJ3'><span id='87VJ3'><b id='87VJ3'><form id='87VJ3'><ins id='87VJ3'></ins><ul id='87VJ3'></ul><sub id='87VJ3'></sub></form><legend id='87VJ3'></legend><bdo id='87VJ3'><pre id='87VJ3'><center id='87VJ3'></center></pre></bdo></b><th id='87VJ3'></th></span></q></dt></tr></i><div id='87VJ3'><tfoot id='87VJ3'></tfoot><dl id='87VJ3'><fieldset id='87VJ3'></fieldset></dl></div>
      1. 如何从 Python 中的字符串中获取整数值?

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

                1. 本文介绍了如何从 Python 中的字符串中获取整数值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  假设我有一个字符串

                  string1 = "498results should get" 
                  

                  现在我只需要从像 498 这样的字符串中获取整数值.在这里我不想使用 list slicing 因为整数值可能会像这些示例一样增加:

                  Now I need to get only integer values from the string like 498. Here I don't want to use list slicing because the integer values may increase like these examples:

                  string2 = "49867results should get" 
                  string3 = "497543results should get" 
                  

                  所以我只想以完全相同的顺序从字符串中获取整数值.我的意思是像 498,49867,497543 分别来自 string1,string2,string3.

                  So I want to get only integer values out from the string exactly in the same order. I mean like 498,49867,497543 from string1,string2,string3 respectively.

                  谁能用一两行告诉我如何做到这一点?

                  Can anyone let me know how to do this in a one or two lines?

                  推荐答案

                  >>> import re
                  >>> string1 = "498results should get"
                  >>> int(re.search(r'd+', string1).group())
                  498
                  

                  如果字符串中有多个整数:

                  If there are multiple integers in the string:

                  >>> map(int, re.findall(r'd+', string1))
                  [498]
                  

                  这篇关于如何从 Python 中的字符串中获取整数值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:为什么(0-6)是-6 = False? 下一篇:+ 不支持的操作数类型:“int"和“str"

                  相关文章

                  最新文章

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

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

                      <tfoot id='V1Q0x'></tfoot>