網站首頁 編程語言 正文
目錄
- 前言
- 一、檢驗是否全是中文字符
- 二、檢驗是否含有中文字符
- 三、檢測是否全是英文字符
- 四、檢測是否含有英文字符
前言
博主工作中剛好用到了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語句獲取表結構
相關推薦
- 2022-05-09 go單例實現雙重檢測是否安全的示例代碼_Golang
- 2022-03-29 Android頂部標題欄的布局設計_Android
- 2022-09-19 C語言數據結構之單鏈表存儲詳解_C 語言
- 2022-05-31 C語言實現帶頭雙向循環鏈表_C 語言
- 2023-02-10 docker的鏡像存放地址在哪里_docker
- 2024-07-15 linux系統管理高級命令(練習)(six day)
- 2022-04-27 解決linux下redis數據庫overcommit_memory問題_Redis
- 2022-08-03 python中time庫使用詳解_python
- 最近更新
-
- 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同步修改后的遠程分支