字符串详解
1. index
def index(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
"""
S.index(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.
Raises ValueError when the substring is not found.
"""
return 0
翻译:格式s.index(sub,开始位置,结束位置)--》返回整型
返回sub字符所在位置的最小位置
并且sub所在【开始:结束】范围内,可选参数开始位置和结束位置解释为切片表示法
1 #!/usr/bin/python 2 #字符串 3 str='wo ai beii Jing Tian an men' 4 print(str.index('i',4,9))View Code
2.isdigit
def isdigit(self, *args, **kwargs): # real signature unknown
"""
Return True if the string is a digit string, False otherwise.
A string is a digit string if all characters in the string are digits and there
is at least one character in the string.
"""
pass
翻译:如果字符串是数字字符串则返回True,否则返回False
如果字符串里面的所有字符都是数字,则是个数字字符串,并且这个字符串不为空字符串。
1 #!/usr/bin/python 2 #字符串 3 str='wo ai beii Jing Tian an men 123456' 4 print(str.isdigit())#是否数字View Code
3.isalnum
def isalnum(self, *args, **kwargs): # real signature unknown
"""
Return True if the string is an alpha-numeric string, False otherwise.
A string is alpha-numeric if all characters in the string are alpha-numeric and
there is at least one character in the string.
"""
pass
翻译:如果字符串是字母数字的则返回True,否则返回False
如果字符串里面只包含字母和数字,则是字母数字字符串,并且这个字符串不为空字符串。
1 #!/usr/bin/python 2 #字符串 3 str='wo ai beii Jing Tian an men 123456' 4 print(str.isalpha())View Code
4.isalpha
def isalpha(self, *args, **kwargs): # real signature unknown
"""
Return True if the string is an alphabetic string, False otherwise.
A string is alphabetic if all characters in the string are alphabetic and there
is at least one character in the string.
"""
pass
翻译:如果字符串是字母,则返回True,否则返回False
如果字符串里面只包含字母,则是字母字符串,并且这个字符串不为空字符串
1 #!/usr/bin/python 2 #字符串 3 str='wo ai beii Jing Tian an men 123456' 4 print(str.isalpha())View Code
5.isascii
def isascii(self, *args, **kwargs): # real signature unknown
"""
Return True if all characters in the string are ASCII, False otherwise.
ASCII characters have code points in the range U+0000-U+007F.
Empty string is ASCII too.
"""
pass
翻译:如果字符串是ASCII则返回True,否则返回False
ASCII字符串是码值范围在U+0000-U+007F间,空字符串也是ASCII
1 #!/usr/bin/python 2 #字符串 3 str='wo ai beii Jing Tian an men 123456' 4 print(str.isascii())View Code
6.join
def join(self, ab=None, pq=None, rs=None): # real signature unknown; restored from __doc__
"""
Concatenate any number of strings.
The string whose method is called is inserted in between each given string.
The result is returned as a new string.
Example: '.'.join(['ab', 'pq', 'rs']) -> 'ab.pq.rs'
"""
pass
翻译:将任意字符的字符串连接起来
被调用方法的字符串被插入每个给的字符串中间,结果返回一个新的字符串
比如'.'.join('abc')-->'a.b.c'在a与b之间插入.以及在b与c之间插入.
1 #!/usr/bin/python 2 #字符串 3 str='wo ai beii Jing Tian an men' 4 str1='abcd' 5 print(str.join(str1))View Code
7.ljust/rjust
def ljust(self, *args, **kwargs): # real signature unknown
"""
Return a left-justified/right-justified string of length width.
Padding is done using the specified fill character (default is a space).
"""
pass
翻译:返回长度为width的左对齐字符串
用指定字符填充(默认为空格)
1 #!/usr/bin/python 2 #字符串 3 str='wo ai beii Jing Tian an men' 4 print(str.ljust(30,'-')) 5 print(str.rjust(30,'-'))View Code
8.partition
def partition(self, *args, **kwargs): # real signature unknown
"""
Partition the string into three parts using the given separator.
This will search for the separator in the string. If the separator is found,
returns a 3-tuple containing the part before the separator, the separator
itself, and the part after it.
If the separator is not found, returns a 3-tuple containing the original string
and two empty strings.
"""
pass
翻译:用给的分隔符将字符串分成3部分;
这将要求在字符串中找分割符,如果分隔符找到,则返回3个源组包含分隔符的部分(分隔符前面部分,分隔符和分隔符后面的部分)
如果分隔符没有被找到,则返回一个原始字符串及2个空字符串
1 #!/usr/bin/python 2 #字符串 3 str='wo ai beii Jing Tian an men' 4 print(str.partition('i'))View Code
9.removeprefix
def removeprefix(self, *args, **kwargs): # real signature unknown
"""
Return a str with the given prefix string removed if present.
If the string starts with the prefix string, return string[len(prefix):].
Otherwise, return a copy of the original string.
"""
pass
翻译:如果给定的前缀存在,则返回一个删除该字符的字符串
如果字符串是以给定的字符开头,则返回字符串[len(prefix):],否则返回原始字符串
1 #!/usr/bin/python 2 #字符串 3 str='wo ai beii Jing Tian an men' 4 print(str.removeprefix('wo'))View Code
10.removesuffix
def removesuffix(self, *args, **kwargs): # real signature unknown
"""
Return a str with the given suffix string removed if present.
If the string ends with the suffix string and that suffix is not empty,
return string[:-len(suffix)]. Otherwise, return a copy of the original
string.
"""
pass
翻译:如果是以给定字符结尾的则返回删除这个字符的字符串
如果字符串是以给定的字符结尾的,则返回删除该字符的字符串,否则返回原始字符串
1 #!/usr/bin/python 2 #字符串 3 str='wo ai beii Jing Tian an men' 4 print(str.removesuffix('n'))View Code
11.strip
def strip(self, *args, **kwargs): # real signature unknown
"""
Return a copy of the string with leading and trailing whitespace removed.
If chars is given and not None, remove characters in chars instead.
"""
pass
翻译:返回一个删除开头和结尾为空的字符串
如果给定字符存在,则删除字符串中给定字符
1 #!/usr/bin/python 2 #字符串 3 str=' wo ai beii Jing Tian an men ' 4 print(str.strip())View Code
12.split
def split(self, *args, **kwargs): # real signature unknown
"""
Return a list of the words in the string, using sep as the delimiter string.
sep
The delimiter according which to split the string.
None (the default value) means split according to any whitespace,
and discard empty strings from the result.
maxsplit
Maximum number of splits to do.
-1 (the default value) means no limit.
"""
pass
翻译:使用sep最为分隔字符串的,返回由字符串中字符组成的列表
分隔符是分隔字符串的,默认以空格进行分隔,并且在结果中丢弃空字符。
最大分隔,指分隔的最大数,-1(默认值)为没有限制
1 #!/usr/bin/python 2 #字符串 3 str='wo ai beii Jing Tian an men' 4 print(str.split())View Code
13.splitlines
def splitlines(self, *args, **kwargs): # real signature unknown
"""
Return a list of the lines in the string, breaking at line boundaries.
Line breaks are not included in the resulting list unless keepends is given and
true.
"""
pass
翻译:以行为边界,返回字符串中一行的列表
结果不会包含分隔符,除非keepends给定为True
1 #!/usr/bin/python 2 #字符串 3 str='wo ai beii Jing Tian an men\ntian an men tai yang sheng' 4 print(str.splitlines(keepends=False)) #keepends是否保留分隔符(\r \r\n \n) \r--换行 \n--回车View Code
14.swapcase
def swapcase(self, *args, **kwargs): # real signature unknown
""" Convert uppercase characters to lowercase and lowercase characters to uppercase. """
pass
翻译:大小写转换
1 #!/usr/bin/python 2 #字符串 3 str='wo ai beii Jing Tian an men\ntian an men tai yang sheng' 4 print(str.swapcase())View Code
15.translate
def translate(self, *args, **kwargs): # real signature unknown
"""
Replace each character in the string using the given translation table.
table
Translation table, which must be a mapping of Unicode ordinals to
Unicode ordinals, strings, or None.
The table must implement lookup/indexing via __getitem__, for instance a
dictionary or list. If this operation raises LookupError, the character is
left untouched. Characters mapped to None are deleted.
"""
pass
翻译:用给的表单替换字符串的字符
表单:翻译的表单必须是unicode序列的字典映射
表单必须是通过__getitem__查找,比如说字典或列表,如果这种操作导致lookup错误,那么字符没有影响,映射到none的字符将被删除
1 str='wo ai beii Jing Tian an men\ntian an men tai yang sheng' 2 intab ="aeiou" 3 outtab='12345' 4 trantab=str.maketrans(intab,outtab) 5 print(trantab) 6 print(str.translate(trantab))View Code 标签:string,python,men,print,str,字符串 From: https://www.cnblogs.com/Little-Girl/p/17974938