字符串详解
1.center
def center(self, *args, **kwargs): # real signature unknown
"""
Return a centered string of length width.
Padding is done using the specified fill character (default is a space).
"""
pass
翻译:1.返回长度未width(第一个参数)的居中字符串
2.使用指定的填充字符(第二个参数,默认为空格)进行填充
1 #!/usr/bin/python 2 str='wo ai bei Jing Tian an men' 3 print(str.center(100,'-'))#据中打印并以-填充到100个字符View Code
2.capitalize
def capitalize(self, *args, **kwargs): # real signature unknown
"""
Return a capitalized version of the string.
More specifically, make the first character have upper case and the rest lower
case.
"""
pass
翻译:1.返回字符串一个大写版本
2.详细一点来说就是是每个字符串首字母大写,其余小写
1 #!/usr/bin/python 2 str='wo ai bei Jing Tian an men' 3 print(str.capitalize())#首字母大写View Code
3.upper
def upper(self, *args, **kwargs): # real signature unknown
""" Return a copy of the string converted to uppercase. """
翻译:1.返回转换为大写字母的副本
1 #!/usr/bin/python 2 str='wo ai bei Jing Tian an men' 3 print(str.upper())View Code
4.lower
def lower(self, *args, **kwargs): # real signature unknown
""" Return a copy of the string converted to lowercase. """
pass
翻译:返回转换为小写字母的副本
1 #!/usr/bin/python 2 str='wo ai bei Jing Tian an men' 3 print(str.lower())View Code
5.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.
"""
return 0
翻译:语法s.count(统计的字母,开始序号哦,结束序号)--》返回值是整型
返回字符sub在范围【开始-结束】间的不重复出现的次数,可选参数开始和结束可解释为切片表示法
1 #!/usr/bin/python 2 str='wo ai beii Jing Tian an men' 3 print(str.count('i',0,10))View Code
6.find
def find(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
"""
S.find(sub[, start[, end]]) -> int
Return the lowest index in S where substring sub is found,
such that sub is contained within S[start:end]. Optional
arguments start and end are interpreted as in slice notation.
Return -1 on failure.
"""
return 0
翻译:语法s.find(查找的字符sub,开始位置,结束位置)-->返回整型
返回字符sub在范围内被发现的最小的索引,可选参数开始位置和结束位置可解释为切片表示法
1 #!/usr/bin/python 2 str='wo ai beii Jing Tian an men' 3 print(str.find('i'))View Code
7.replace
def replace(self, *args, **kwargs): # real signature unknown
"""
Return a copy with all occurrences of substring old replaced by new.
count
Maximum number of occurrences to replace.
-1 (the default value) means replace all occurrences.
If the optional argument count is given, only the first count occurrences are
replaced.
"""
pass
翻译:返回字符串所有出现的旧值被新值覆盖的副本
count 出现最大数被替代,-1(默认值)意思是所有出现的都被替代。
如果可选参数被给出,那么只替换第一次出现的值
语法:s.replace(旧值,新值,出现个数(从左边开始)默认-1为所有替换)
1 #!/usr/bin/python 2 str='wo ai beii Jing Tian an men' 3 print('replace用法:',str.replace('i','I',1))View Code
8.format
def format(self, *args, **kwargs): # known special case of str.format
"""
S.format(*args, **kwargs) -> str
Return a formatted version of S, using substitutions from args and kwargs.
The substitutions are identified by braces ('{' and '}').
"""
pass
翻译:将字符串里面用{}的替换为args或kwargs替换
1 #!/usr/bin/python 2 str='{} ai bei Jing Tian an men' 3 print(str.format('wo')) 4 str='name is {},age is {} ' 5 print('format用法:',str.format('ll',22))#按位置参数赋值 6 str='name is {1},age is {0} ' 7 print('format用法:',str.format(22,'ll'))#按位置参数赋值View Code
9.format_map
def format_map(self, mapping): # real signature unknown; restored from __doc__
"""
S.format_map(mapping) -> str
Return a formatted version of S, using substitutions from mapping.
The substitutions are identified by braces ('{' and '}').
"""
return ""
翻译:将字符串里面用{}的替换为map
1 #!/usr/bin/python 2 str='name is {name},age is {age} ' 3 print(str.format_map({'name':'ll','age':22}))View Code