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

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

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

      2. <i id='jOqcW'><tr id='jOqcW'><dt id='jOqcW'><q id='jOqcW'><span id='jOqcW'><b id='jOqcW'><form id='jOqcW'><ins id='jOqcW'></ins><ul id='jOqcW'></ul><sub id='jOqcW'></sub></form><legend id='jOqcW'></legend><bdo id='jOqcW'><pre id='jOqcW'><center id='jOqcW'></center></pre></bdo></b><th id='jOqcW'></th></span></q></dt></tr></i><div id='jOqcW'><tfoot id='jOqcW'></tfoot><dl id='jOqcW'><fieldset id='jOqcW'></fieldset></dl></div>
      3. 你如何使用:isalnum、isdigit、isupper 来测试字符串的每个字符?

        时间:2023-09-02

        <small id='6xQPO'></small><noframes id='6xQPO'>

        • <bdo id='6xQPO'></bdo><ul id='6xQPO'></ul>

                <tbody id='6xQPO'></tbody>
                <legend id='6xQPO'><style id='6xQPO'><dir id='6xQPO'><q id='6xQPO'></q></dir></style></legend>

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

              1. <tfoot id='6xQPO'></tfoot>

                  本文介绍了你如何使用:isalnum、isdigit、isupper 来测试字符串的每个字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试制作一个密码强度模拟器,它要求用户输入密码,然后返回分数.

                  I am trying to make a password strength simulator which asks the user for a password and then gives back a score.

                  我正在使用:

                  islanum() 
                  isdigit()
                  isupper() 
                  

                  试试看输入的密码有多好.

                  to try and see how good the inputted password is.

                  我希望它不是返回布尔值,而是评估密码的每个字符,然后程序将所有真"值相加并将其转换为分数.示例代码:

                  Instead of returning boolean values, I want this to assess each characters of the password, and then the program to add up all the "True" values and turn it into a score. EXAMPLE CODE:

                  def upper_case():
                      points = int(0)
                      limit = 3
                      for each in pword:
                          if each.isupper():
                              points = points + 1
                              return points
                          else:
                              return 0
                  

                  任何帮助将不胜感激!谢谢!!

                  Any help would be much appreciated!! THANKS!!

                  推荐答案

                  .isalnum(), .isupper(), .isdigit() 和朋友是 Python 中 str 类型的方法,调用方式如下:

                  .isalnum(), .isupper(), .isdigit() and friends are methods of the str type in Python and are called like this:

                  >>> s = "aBc123"
                  >>> s[0].isalnum()
                  True
                  >>> s[1].isupper()
                  True
                  >>> s[3].isdigit()
                  True
                  

                  简单的getscore()功能:

                  Simple getscore() Function:

                  s = "aBc123@!xY"
                  
                  def getscore(s):
                      score = 0
                      for c in s:
                          if c.isupper():
                              score += 2
                          elif c.isdigit():
                              score += 2
                          elif c.isalpha():
                              score += 1
                          else:
                              score += 3
                      return score
                  
                  print getscore(s)
                  

                  输出:

                  13
                  

                  更好的版本:

                  s = "aBc123@!xY"
                  
                  
                  def getscore(s):
                      return len(s) + len([c for c in s if c.isdigit() or c.isupper() or not c.isalpha()])
                  
                  print getscore(s)
                  

                  输出:

                  17
                  

                  这篇关于你如何使用:isalnum、isdigit、isupper 来测试字符串的每个字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:没有返回任何内容时的文档字符串 下一篇:python3中的可选yield或return.如何?

                  相关文章

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

                  <legend id='hSKqK'><style id='hSKqK'><dir id='hSKqK'><q id='hSKqK'></q></dir></style></legend>

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