capitalize()
将字符串第一个字母转换为大写,其他不变
def capitalize(self): # real signature unknown; restored from __doc__
"""
S.capitalize() -> str
Return a capitalized version of S, i.e. make the first character
have upper case and the rest lower case.
"""
return ""
例:
#!/usr/bin/env python i = 'this is a test' print( i.capitalize()) #输出结果: This is a test
casefold()
将字符串全部转换为小写,该方法与lower()方法的效果类似,但也有不同。
官方说明:https://docs.python.org/3/library/stdtypes.html#str.casefold
def casefold(self): # real signature unknown; restored from __doc__
"""
S.casefold() -> str
Return a version of S suitable for caseless comparisons.
"""
return ""
例:
#!/usr/bin/env python i = 'THIS IS A TEST' print( i.casefold()) #输出结果: this is a test
center()
以给定为中心,输出一个宽度为width的字符串,并使用fillchar指定的字符填充,fillchar默认为空白
def center(self, width, fillchar=None): # real signature unknown; restored from __doc__
"""
S.center(width[, fillchar]) -> str
Return S centered in a string of length width. Padding is
done using the specified fill character (default is a space)
"""
return ""
例:
#!/usr/bin/env python
i = 'Test'
print(12345678901234567890)
print(i.center(20))
print(i.center(20,'*'))
#输出结果:
12345678901234567890
Test
********Test********
count()
该方法返回给定字符在字符中出现的次数,并可以指定在字符串中统计次数的范围
def count(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
"""
S.count(sub[, start[, end]]) -> int
Return the number of non-overlapping occurrences of substring sub in
string S[start:end]. Optional arguments start and end are
interpreted as in slice notation.
"""
例:
#!/usr/bin/env python
i = 'this is a Test'
print(i.count('t'))
print(i.count('T'))
print(i.count('s'))
print(i.count('s',4,9))
print(i.count('s',4,))
#输出结果:
2
1
3
1
2
encode()
该方法
浙公网安备 33010602011771号