对于首字母的小写有两个函数可以用:capitalize(),title().
这两个函数有区别:
capitcalize()是对该字符串的第一个字母操作
title()是对该字符串中的所有单词的首字母操作
>>> s = "you are beautiful"
>>> type(s)
>>> s.capitalize()
"You are beautiful"
>>> s.title()
"You Are Beautiful"
>>> len(s)
17 #空格也为字符
------------------------------------------------------------------------------------------------------------
如果是多字符串组成的元组也可以操作,使用for循环:
>>> s = "you are sb","you ARE beaUtiful"
>>> type(s)
>>> for i in s:
... print(i.capitalize())
...
You are sb
You are beautiful
>>> for i in s:
... print(i.title())
...
You Are Sb
You Are Beautiful
------------------------------------------