教程集 www.jiaochengji.com
教程集 >  Python编程  >  Python入门  >  正文 python怎么判断字符串中包含特殊符号

python怎么判断字符串中包含特殊符号

发布时间:2021-02-18   编辑:jiaochengji.com
教程集为您提供python怎么判断字符串中包含特殊符号等资源,欢迎您收藏本站,我们将为您提供最新的python怎么判断字符串中包含特殊符号资源

python判断字符串中包含特殊符号的方法:首先使用“for i in string”命令来遍历输入的字符串;然后输入“if i in input_psd”命令对输入的语句进行判断即可。

这里不导入其他模块,预先定义好你所认为是特殊字符的字符就好

input_psd = input("请输入字符串")
# 判断是否有特殊字符
    string = "~!@#$%^&*()_ -*/<>,.[]\/"
    for i in string:
        if i in input_psd:
            print("您的输入包含特殊字符")

或者导入python内置模块re

import re
input_psd = input("请输入字符串")
test_str = re.search(r"\W",input_psd)
if test_str==None:
    print("没有没有真没有特殊字符")
else:
    print("该文本包含特殊字符")

您可能感兴趣的文章:
python怎么判断字符串中包含特殊符号
JavaScript 特殊字符示例
php表单提交特殊字符过滤方法
js判断是否包含特殊字符
js特殊字符转义类型
js正则表达式特殊字符过滤代码
Python字符串详解
python怎么把字符串换行输出
js过滤特殊字符输入
python怎么转义

[关闭]
~ ~