![fb2e0a146b6879dff0ca0af641c23278.png](https://img-blog.csdnimg.cn/img_convert/fb2e0a146b6879dff0ca0af641c23278.png)
![da70dc787218ce939bf271c2e6a75393.png](https://img-blog.csdnimg.cn/img_convert/da70dc787218ce939bf271c2e6a75393.png)
这里不导入其他模块,预先定义好你所认为是特殊字符的字符就好
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怎么判断字符串中包含特殊符号-Python学习网www.py.cn![fa00440556d6a9fff60b90dddeb3dfc7.png](https://img-blog.csdnimg.cn/img_convert/fa00440556d6a9fff60b90dddeb3dfc7.png)