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
转载于:https://www.cnblogs.com/zhtf2014/archive/2010/12/23/1915318.html
转载请注明原文地址: https://win8.8miu.com/read-1450361.html