<legend id='M6gq8'><style id='M6gq8'><dir id='M6gq8'><q id='M6gq8'></q></dir></style></legend>
  • <tfoot id='M6gq8'></tfoot>
  • <small id='M6gq8'></small><noframes id='M6gq8'>

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

      1. 如何检查字符串是否仅包含 Python 中的字母?

        How can I check if a string only contains letters in Python?(如何检查字符串是否仅包含 Python 中的字母?)

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

                • <bdo id='FRdxn'></bdo><ul id='FRdxn'></ul>
                    <tbody id='FRdxn'></tbody>

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

                  <tfoot id='FRdxn'></tfoot>
                  本文介绍了如何检查字符串是否仅包含 Python 中的字母?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试检查一个字符串是否只包含字母,而不是数字或符号.

                  I'm trying to check if a string only contains letters, not digits or symbols.

                  例如:

                  >>> only_letters("hello")
                  True
                  >>> only_letters("he7lo")
                  False
                  

                  推荐答案

                  简单:

                  if string.isalpha():
                      print("It's all letters")
                  

                  str.isalpha() 只为真如果字符串中的所有个字符都是字母:

                  如果字符串中的所有字符都是字母并且至少有一个字符,则返回 true,否则返回 false.

                  Return true if all characters in the string are alphabetic and there is at least one character, false otherwise.

                  演示:

                  >>> 'hello'.isalpha()
                  True
                  >>> '42hello'.isalpha()
                  False
                  >>> 'hel lo'.isalpha()
                  False
                  

                  这篇关于如何检查字符串是否仅包含 Python 中的字母?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Initialize Multiple Numpy Arrays (Multiple Assignment) - Like MATLAB deal()(初始化多个 Numpy 数组(多重赋值) - 像 MATLAB deal())
                  How to extend Python class init(如何扩展 Python 类初始化)
                  What#39;s the difference between dict() and {}?(dict() 和 {} 有什么区别?)
                  What is a wrapper_descriptor, and why is Foo.__init__() one in this case?(什么是 wrapper_descriptor,为什么 Foo.__init__() 在这种情况下是其中之一?)
                  Initialize list with same bool value(使用相同的布尔值初始化列表)
                  setattr with kwargs, pythonic or not?(setattr 与 kwargs,pythonic 与否?)
                  <legend id='L5s1i'><style id='L5s1i'><dir id='L5s1i'><q id='L5s1i'></q></dir></style></legend>
                    <bdo id='L5s1i'></bdo><ul id='L5s1i'></ul>

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

                    <tfoot id='L5s1i'></tfoot>

                        <tbody id='L5s1i'></tbody>

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