ITPub博客

首页 > 应用开发 > > python用函数怎么判断大小写

python用函数怎么判断大小写

作者:u_151d1ef45539 时间:2019-10-21 10:28:10 0 删除 编辑

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

例如:

>>> str_1 = "HELLO PYTHON" # 全大写

>>> str_2 = "Hello PYTHON" # 大小写混合

>>> str_3 = "Hello Python" # 单词首字母大写

>>> str_4 = "hello python" # 全小写

isupper() 判断是否全是大写

>>> str_1.isupper()

True

>>> str_2.isupper()

False

>>> str_3.isupper()

False

>>> str_4.isupper()

False

islower()判断是否全是小写

>>> str_1.islower()

False

>>> str_2.islower()

False

>>> str_3.islower()

False

>>> str_4.islower()

True

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

>>> str_1.istitle()

False

>>> str_2.istitle()

False

>>> str_3.istitle()

True

>>> str_4.istitle()

False

以上就是python用函数怎么判断大小写的详细内容,更多请关注其它相关文章!

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69927053/viewspace-3151419/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: css样式说明介绍
请登录后发表评论 登录
全部评论

注册时间:2019-07-31

  • 博文量
    155
  • 访问量
    256