鱼C论坛

 找回密码
 立即注册
查看: 1008|回复: 6

[已解决]关于空格判定

[复制链接]
发表于 2018-8-18 23:59:25 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
第一个字符,是空格判定成功  但是第二个或者在字符串中包含判定不到,问问大神们怎么修改好一点
最佳答案
2018-8-19 00:20:21
本帖最后由 claws0n 于 2018-8-19 00:24 编辑

passwd = input()
length = len(passwd)
while True:
    if ' ' in passwd:
        print('space found')
        continue
    if length <= 8:
        ...
# 如果输入成功/合法
    break

效率上的安排应该
passwd = input()

while True:
    if ' ' in passwd:
        print('space found')
        passwd = input()
        continue
    length = len(passwd) #合法的输入才去判断长度
    if length <= 8:
        ...
空格判定1.png
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2018-8-19 00:20:21 | 显示全部楼层    本楼为最佳答案   
本帖最后由 claws0n 于 2018-8-19 00:24 编辑

passwd = input()
length = len(passwd)
while True:
    if ' ' in passwd:
        print('space found')
        continue
    if length <= 8:
        ...
# 如果输入成功/合法
    break

效率上的安排应该
passwd = input()

while True:
    if ' ' in passwd:
        print('space found')
        passwd = input()
        continue
    length = len(passwd) #合法的输入才去判断长度
    if length <= 8:
        ...
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-8-19 00:47:54 | 显示全部楼层
claws0n 发表于 2018-8-19 00:20
passwd = input()
length = len(passwd)
while True:

非常感谢,甲鱼老师代码这么写,奇怪,问问鱼油,
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-8-19 00:53:19 | 显示全部楼层
claws0n 发表于 2018-8-19 00:20
passwd = input()
length = len(passwd)
while True:

空格判定OK .png
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-8-19 01:05:31 | 显示全部楼层
本帖最后由 claws0n 于 2018-8-19 01:08 编辑
Stubborn 发表于 2018-8-19 00:47
非常感谢,甲鱼老师代码这么写,奇怪,问问鱼油,


没有做过,不清楚~
应该是你多了空格 passwd.isspace() 一个字,点后面没有空格
尝试一下原来的版本
如果把 len(passwd) 放到循环体内部,就把外部的删除吧  ^_^

另外,如果后面的强度判断不是在 while 的内部,不能那样写,会造成死循环
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-8-19 16:26:54 | 显示全部楼层
claws0n 发表于 2018-8-19 01:05
没有做过,不清楚~
应该是你多了空格 passwd.isspace() 一个字,点后面没有空格
尝试一下原来的版本
...

isspace()  如果字符串中只包含空格,则返回 True,否则返回 False。· 这种情况是不是问题出在只上面,只包含空格,而不是含有空格。  非常感谢,又学会了一招; 判别一串字符含有某个字符 都可以用  :
if  '**' in ***   这种格式是吗?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-8-19 16:33:41 | 显示全部楼层
Stubborn 发表于 2018-8-19 16:26
isspace()  如果字符串中只包含空格,则返回 True,否则返回 False。· 这种情况是不是问题出在只上面, ...

那些内置函数基本上有得找~
对,比如说现在的密码要求要有特殊符号
if '密码' in 特殊符号:
    ....

学得不错,加油 ^_^
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-4-1 12:39

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表