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从零开始学习编程(黑马程序员)
下一篇 python怎么分读txt中逗号
