網站首頁 編程語言 正文
目錄
- 前言
- 一、檢驗是否全是中文字符
- 二、檢驗是否含有中文字符
- 三、檢測是否全是英文字符
- 四、檢測是否含有英文字符
前言
博主工作中剛好用到了Python檢測中英文文的小技巧,記錄一下
一、檢驗是否全是中文字符
def is_all_chinese(strs):
for _char in strs:
if not '\u4e00' <= _char <= '\u9fa5':
return False
return True
print(is_all_chinese("hello"))
print(is_all_chinese("hello你好"))
print(is_all_chinese("123456"))
print(is_all_chinese("你好"))
輸出結果:
False
False
False
True
二、檢驗是否含有中文字符
def is_contains_chinese(strs):
for _char in strs:
if '\u4e00' <= _char <= '\u9fa5':
return True
return False
print(is_contains_chinese("hello"))
print(is_contains_chinese("hello你好"))
print(is_contains_chinese("123456"))
print(is_contains_chinese("你好"))
輸出結果:
False
True
False
True
三、檢測是否全是英文字符
def is_all_english(strs):
import string
for i in strs:
if i not in string.ascii_lowercase + string.ascii_uppercase:
return False
return True
print(is_all_english("hello"))
print(is_all_english("hello你好"))
print(is_all_english("123456"))
print(is_all_english("你好"))
輸出結果:
True
False
False
False
四、檢測是否含有英文字符
def is_contains_english(strs):
if (u'\u0041' <= strs <= u'\u005a') or (u'\u0061' <= strs <= u'\u007a'):
return True
else:
return False
print(is_contains_english("hello"))
print(is_contains_english("hello你好"))
print(is_contains_english("123456"))
print(is_contains_english("你好"))
輸出結果:
True
True
False
False
原文鏈接:https://blog.csdn.net/yuan2019035055/article/details/122294472
- 上一篇:Matplotlib安裝與配置
- 下一篇:SQL語句獲取表結構
相關推薦
- 2023-03-04 Qt利用tablewidget模擬手指實現滑動_C 語言
- 2023-01-14 Python?pandas中to_sql的使用及問題詳解_python
- 2022-10-22 Golang?中反射的應用實例詳解_Golang
- 2022-08-23 Selenium多窗口切換解決方案_python
- 2023-02-26 Go實現簡單的數據庫表轉結構體詳解_Golang
- 2022-01-31 微信小程序獲取二維碼中URL中帶的參數
- 2022-06-01 Python學習之內置函數總結_python
- 2022-12-27 go?build失敗報方法undefined的解決過程_Golang
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支