首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >python函数——字符串字母大小判断

python函数——字符串字母大小判断

作者头像
莫斯
发布2020-09-10 10:45:42
发布2020-09-10 10:45:42
1.4K0
举报
文章被收录于专栏:备份备份

Python提供了isupper()islower()istitle()方法用来判断字符串的大小写, 具体实例如下:

代码语言:javascript
复制
>>> str_1 = "HELLO PYTHON" # 全大写
>>> str_2 = "Hello PYTHON" # 大小写混合
>>> str_3 = "Hello Python" # 单词首字母大写
>>> str_4 = "hello python" # 全小写

1. isupper() 判断是否全是大写

代码语言:javascript
复制
>>> str_1.isupper()
True
>>> str_2.isupper()
False
>>> str_3.isupper()
False
>>> str_4.isupper()
False

2. islower()判断是否全是小写

代码语言:javascript
复制
>>> str_1.islower()
False
>>> str_2.islower()
False
>>> str_3.islower()
False
>>> str_4.islower()
True

3. istitle()判断首字母是否大写, 其余的是否小写

代码语言:javascript
复制
>>> str_1.istitle()
False
>>> str_2.istitle()
False
>>> str_3.istitle()
True
>>> str_4.istitle()
False
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/01/30 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1. isupper() 判断是否全是大写
  • 2. islower()判断是否全是小写
  • 3. istitle()判断首字母是否大写, 其余的是否小写
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档