字符串的lower方法可以使字符串中的所有字母转换为小写,返回字符串
'AB2C3D'.lower()
#'ab2d3c'
字符串的title方法可以使字符串中的单词标题化,即连续的字母字符串的首字母大写(不管是否真的为单词)
'ab2c3d'.title()
#'Ab2C3D'
B title是将每个单词首字母变大,其余变小,实际的意思是【非字母后的第一个字母将转换为大写字母】
python 认为数字和空格一样,是单词的结束标记。只能这样解释了,看以下测试:
>>> help(str.title)
Help on method_descriptor:
title(self, /)
Return a version of the string where each word is titlecased.
More specifically, words start with uppercased characters and all remaining
cased characters have lower case.
>>> 'AB2C3D'.lower().title()
'Ab2C3D'
>>> 'AB C D'.lower().title()
'Ab C D'
>>> 'AB CCCC DDDD'.lower().title()
'Ab Cccc Dddd'
>>> 'AB2CCCC2DDDD'.lower().title()
'Ab2Cccc2Dddd'
>>> 'AB2CCCC2DD3DD'.lower().title()
'Ab2Cccc2Dd3Dd'