python3 判断字符串是否包含中英文和数字
生活随笔
收集整理的這篇文章主要介紹了
python3 判断字符串是否包含中英文和数字
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
import redef check_contain_chinese(check_str):"""判斷字符串中是否含有中文字符"""for ch in check_str:if u'\u4e00' <= ch <= u'\u9fff':return Truereturn Falsedef check_contain_englist(check_str):"""判斷字符串中是否含有英文字符"""contain_en = bool(re.search('[a-z]', check_str))return contain_endef check_contain_digits(check_str):"""判斷字符串中是否含有數字字符"""contain_di = bool(re.search('[0-9]', check_str))return contain_didef check_contain_valid_str(check_str):"""判斷字符串是否包含有效字符:中文 or 英文 or 數字"""valid_res = check_contain_englist(check_str) or check_contain_chinese(check_str) or check_contain_digits(check_str)return valid_resif __name__ == "__main__":text = '中國人的飯碗任何時候都要牢牢端在自己手中。%'print(check_contain_valid_str(text))text = '1。%'print(check_contain_valid_str(text))text = 'a。%'print(check_contain_valid_str(text))text = '中國人的飯碗任何時候都要牢牢端在自己手中1a。%'print(check_contain_valid_str(text))text = '。%'print(check_contain_valid_str(text))
總結
以上是生活随笔為你收集整理的python3 判断字符串是否包含中英文和数字的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 方正飞腾4.0视频教程
- 下一篇: 最新中国移动光猫改桥接方式(中兴ZXHN