当前位置: 首页 > 图灵资讯 > 行业资讯> python怎么判断字符串中包含特殊符号

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

发布时间:2025-01-22 15:39:07

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

不要在这里导入其他模块,提前定义你认为是特殊字符的字符

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

或导入python内置模块rethon

importre
input_psd=input("请输入字符串")
test_str=re.search(r"\W",input_psd)
iftest_str==None:
print("是不是真的没有特殊字符?")
else:
print("本文包含特殊字符")

推荐课程:Python从零开始学习编程(黑马程序员)

相关文章

如何让vim支持python3

如何让vim支持python3

2025-09-12
python2.7和3.6区别有哪些

python2.7和3.6区别有哪些

2025-09-12
python3有serial库吗

python3有serial库吗

2025-09-12
python中w、r表示什么意思

python中w、r表示什么意思

2025-09-12
python中如何把list变成字符串

python中如何把list变成字符串

2025-09-12
python命名空间是什么

python命名空间是什么

2025-09-12