用 Python 编写程序检查给定的字符串是否为全字母组合

pythonserver side programmingprogramming更新于 2026/1/12 4:28:17

假设我们有一个字符串 s,它代表一个句子,我们必须检查英文字母表中的每个字母是否至少使用过一次。

因此,如果输入是"The grumpy wizards make toxic brew, for the evil queen and Jack",则输出将为 True

为了解决这个问题,我们将遵循以下步骤 −

  • s:= 将 s 中的所有字母变成小写字母
  • a:= 0
  • 对于英文字母表中的每一个 i,执行
    • 如果 i 不在 s 中,则
      • 返回 False
  • 返回 True

让我们看看下面的实现以便更好地理解 −

示例

import string
class Solution:
   def solve(self, s):
      s=s.lower()
      a=0
      for i in string.ascii_lowercase :
         if i not in s :
            return False
      return True
s = "The grumpy wizards make toxic brew, for the evil queen and Jack"
ob = Solution()
print(ob.solve(s))

输入

"The grumpy wizards make toxic brew, for the evil queen and Jack"

输出

True

相关文章


有用资源