新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
創(chuàng)新互聯(lián)Python教程:python怎么判斷字符串中包含特殊符號(hào)
python判斷字符串中包含特殊符號(hào)的方法:首先使用“for i in string”命令來遍歷輸入的字符串;然后輸入“if i in input_psd”命令對(duì)輸入的語(yǔ)句進(jìn)行判斷即可。
這里不導(dǎo)入其他模塊,預(yù)先定義好你所認(rèn)為是特殊字符的字符就好
input_psd = input("請(qǐng)輸入字符串")
# 判斷是否有特殊字符
string = "~!@#$%^&*()_+-*/<>,.[]\/"
for i in string:
if i in input_psd:
print("您的輸入包含特殊字符")或者導(dǎo)入python內(nèi)置模塊re
import re
input_psd = input("請(qǐng)輸入字符串")
test_str = re.search(r"\W",input_psd)
if test_str==None:
print("沒有沒有真沒有特殊字符")
else:
print("該文本包含特殊字符")
推薦課程:Python從零開始學(xué)編程(黑馬程序員)
標(biāo)題名稱:創(chuàng)新互聯(lián)Python教程:python怎么判斷字符串中包含特殊符號(hào)
文章鏈接:http://fisionsoft.com.cn/article/dppdpgj.html


咨詢
建站咨詢

