本文介紹python中字元串的兩個内建函數,str.title( )和str.istitle( )
>>> help(str.title)
Help on method_descriptor:
title(...)
S.title() -> string
Return a titlecased version of S, i.e. words start with uppercase
characters, all remaining cased characters have lowercase.
>>> 'love python!'.title()
'Love Python!'
>>> 'a strange dog'.title()
'A Strange Dog'
>>> help(str.istitle)
Help on method_descriptor:
istitle(...)
S.istitle() -> bool
Return True if S is a titlecased string and there is at least one
character in S, i.e. uppercase characters may only follow uncased
characters and lowercase characters only cased ones. Return False
otherwise.
>>> ''.istitle()
False
>>> 'Love python!'.istitle()
False
>>> 'Love Python!'.istitle()
True
(完)