您的位置:首页 > 编程语言 > Python开发

python str.title( )和str.istitle( )

2016-05-21 20:08 239 查看
本文介绍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

(完)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: