![5d25b180-3217-eb11-8da9-e4434bdf6706.png](http://p05.5ceimg.com/content/5d25b180-3217-eb11-8da9-e4434bdf6706.png)
案例-判断密码强度
![5e25b180-3217-eb11-8da9-e4434bdf6706.png](http://p05.5ceimg.com/content/5e25b180-3217-eb11-8da9-e4434bdf6706.png)
- 案例分析
![6025b180-3217-eb11-8da9-e4434bdf6706.png](http://p02.5ceimg.com/content/6025b180-3217-eb11-8da9-e4434bdf6706.png)
- 知识点
- str.isnumeric()-检测字符串是否由数字组成
- str.isalpha()-检测字符串是否由字母组成
- str.islower()-检测字符串中的所有的字母是否都为小写
- str.upper()-检测字符串中的所有字符是否都为大写
- 更多的isxxx()方法请参考官方帮助文档
- 注意
str.isnumeric()方法检测的时候检测的是整个字符串,检测的是一个整体。
例如:
->c = '12345ad'
->c.isnumeric()
->False
->d = '123456'
->d.isnumeric()
->True
![6125b180-3217-eb11-8da9-e4434bdf6706.png](http://p02.5ceimg.com/content/6125b180-3217-eb11-8da9-e4434bdf6706.png)
str.isalpha()、str.islower()、str.upper()用的是同样的
- 因此要想判断字符串中是否含有数字就要用到循环
![6325b180-3217-eb11-8da9-e4434bdf6706.png](http://p02.5ceimg.com/content/6325b180-3217-eb11-8da9-e4434bdf6706.png)
- 知识点:在函数里面如果提前遇到了return那么就从这里跳出函数并返回return的值
看到这个案例自己的想法代码
![6425b180-3217-eb11-8da9-e4434bdf6706.png](http://p02.5ceimg.com/content/6425b180-3217-eb11-8da9-e4434bdf6706.png)
学习完教程以后的代码
![6625b180-3217-eb11-8da9-e4434bdf6706.png](http://p02.5ceimg.com/content/6625b180-3217-eb11-8da9-e4434bdf6706.png)
总结
加强自己函数化、模块化的思想。