西湖鱼 发表于 2018-8-4 08:52:05

python 中字符串大小写转换

  python中字符串的大小写转换和判断字符串大小写的函数小结:
  


[*]一、pyhton字符串的大小写转换, 常用的有以下几种方法:
[*]
[*]1、对字符串中所有字符(仅对字母有效)的大小写转换,有两个方法:
[*]
[*]print 'just to test it'.upper() #所有字母都转换成大写
[*]JUST TO TEST IT
[*]
[*]print 'JUST TO TEST IT'.lower() #所有字母都转换成小写
[*]just to test it
[*]
[*]2、对字符串中的字符(仅对字母有效)部分大小写转换:
[*]
[*]print 'JUST TO TEST IT'.capitalize() #字符串的首字母转换成大写, 其余转换成小写
[*]Just to test it
[*]
[*]print 'JUST TO TEST IT'.title() #字符串中所有单词的首字母转换成大写, 其余转换成小写
[*]Just To Test It
[*]
[*]二、判断字符串大小写函数:
[*]
[*]print 'JUST TO TEST IT'.isupper()
[*]True
[*]
[*]print 'JUST TO TEST IT'.islower()
[*]False
[*]
[*]print 'JUST TO TEST IT'.istitle()
[*]False
  
页: [1]
查看完整版本: python 中字符串大小写转换