Ray's playground

 

Recipe 1.12. Controlling Case(Python Cookbook)

capitalize
 1 >>> 'one tWo thrEe'.capitalize()
 2 'One two three'
 3 >>> 'hello sunshine'.title()
 4 'Hello Sunshine'
 5 >>> "abc".upper()
 6 'ABC'
 7 >>> "RAY".lower()
 8 'ray'
 9 >>> import string
10 >>> notrans = string.maketrans('''')
11 >>> def containsAny(str, strset):
12     return len(strset) != len(strset.translate(notrans, str))
13 
14 >>> def iscapitalized(s):
15     return s == s.capitalize() and containsAny(s, string.letters)
16 
17 >>> iscapitalized('')
18 False
19 >>> iscapitalized('Hello')
20 True
21 >>> iscapitalized('hello')
22 False

 

posted on 2010-12-23 22:00  Ray Z  阅读(180)  评论(0编辑  收藏  举报

导航