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

来源:互联网 发布:淘宝9月份活动 编辑:程序博客网 时间:2024/06/10 05:57

本文介绍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

(完)


1 0