您的位置:首页 > 编程语言 > Python开发

Python基本数据类型(二)

2017-02-01 13:19 253 查看
一、str[b]的函数说明[/b]字符串是Python中最常用的数据类型,可以使用引号('或")来创建字符串,同时支撑反斜杠(\)转义特殊字符,Python不支持单字符类型,单字符也在Python也是作为一个字符串使用;在python中字符串提供的函数如下:
class str(basestring):
"""
str(object='') -> string

Python2和Python3的用法一致,在Python2中,主要将参数以字符串形式进行返回,如果参数是字符串,则直接返回;
在Python3中,主要为给定对象创建一个新的字符串对象,如果指定了错误的编码,则必须为对象指定数据缓冲区来处理错误编码;否则,返回the result of object.__str__() (if defined) or repr(object)的报错; 默认的encoding为sys.getdefaultencoding();默认的错误类型为"strict";
"""
def capitalize(self): # real signature unknown; restored from __doc__
"""
S.capitalize() -> string

首字母变大写;
例如:
>>> x = 'abc'
>>> x.capitalize()
'Abc'
"""
return ""
def casefold(self): # real signature unknown; restored from __doc__
"""
S.casefold() -> str

把字符串变成小写,用于不区分大小写的字符串比较,与lower()的区别,在汉语、英语环境下面,继续用lower()没问题;要处理其它语言且存在大小写情况的时候需用casefold(); (Python3新增)
例如:
>>> name = 'Test User'
>>> name.casefold()
'test user'
"""
return ""
def center(self, width, fillchar=None): # real signature unknown; restored from __doc__
"""
S.center(width[, fillchar]) -> string

内容居中,width:总长度;fillchar:空白处填充内容,默认无;
例如:
>>> x = 'abc'
>>> x.center(50,'*')
'***********************abc************************'
"""
return ""
def count(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
"""
S.count(sub[, start[, end]]) -> int

用于统计字符串里某个字符出现的次数,可选参数为在字符串搜索的开始与结束位置,即sub参数表示搜索的子字符串;start参数表示字符串开始搜索的位置,默认为第一个字符,第一个字符索引值为0;end参数表示字符串中结束搜索的位置,字符中第一个字符的索引为 0,默认为字符串的最后一个位置;
例如:
>>> x = 'caaaaaaaab'
>>> x.count('a')
8
>>> x.count('a',1,7)
6
"""
return 0
def decode(self, encoding=None, errors=None): # real signature unknown; restored from __doc__
"""
S.decode([encoding[,errors]]) -> object

以encoding指定的编码格式解码字符串,默认编码为字符串编码;即encoding参数指要使用的编码,如"UTF-8";errors参数指设置不同错误的处理方案,默认为 'strict',意为编码错误引起一个UnicodeError,其他值有 'ignore', 'replace', 'xmlcharrefreplace', 'backslashreplace' 以及通过 codecs.register_error() 注册的任何值; (Python2特有,Python3已删除)
例如:
>>> str = 'this is string example!'
>>> str = str.encode('base64','strict')
>>> print 'Encoded String: ' + str
Encoded String: dGhpcyBpcyBzdHJpbmcgZXhhbXBsZSE=
>>> print 'Decoded String: ' + str.decode('base64','strict')
Decoded String: this is string example!
"""
return object()
def encode(self, encoding=None, errors=None): # real signature unknown; restored from __doc__
"""
S.encode([encoding[,errors]]) -> object

以encoding指定的编码格式编码字符串,errors参数可以指定不同的错误处理方案;即encoding参数指要使用的编码,如"UTF-8";errors参数指设置不同错误的处理方案,默认为 'strict',意为编码错误引起一个UnicodeError,其他值有 'ignore', 'replace', 'xmlcharrefreplace', 'backslashreplace' 以及通过codecs.register_error()注册的任何值;
例如:
>>> str = 'this is string example!'
>>> print 'Encoded String: ' + str.encode('base64','strict')
Encoded String: dGhpcyBpcyBzdHJpbmcgZXhhbXBsZSE=
"""
return object()
def endswith(self, suffix, start=None, end=None): # real signature unknown; restored from __doc__
"""
S.endswith(suffix[, start[, end]]) -> bool

用于判断字符串是否以指定后缀结尾,如果以指定后缀结尾返回True,否则返回False,可选参数"start"与"end"为检索字符串的开始与结束位置;即suffix参数指该参数可以是一个字符串或者是一个元素,start参数指字符串中的开始位置,end参数指字符中结束位置;
例如:
>>> str = 'this is string example!'
>>> print str.endswith('e')
False
>>> print str.endswith('e!')
True
>>> print str.endswith('e!',3)
True
>>> print str.endswith('e!',3,8)
False
"""
return False
def expandtabs(self, tabsize=None): # real signature unknown; restored from __doc__
"""
S.expandtabs([tabsize]) -> string

把字符串中的tab符号('\t')转为空格,tab符号('\t')默认的空格数是8,其中tabsize参数指定转换字符串中的tab符号('\t')转为空格的字符数;
例如:
>>> str = 'this is\tstring example!'
>>> print 'Original string: ' + str
Original string: this is        string example!
>>> print 'Defualt exapanded tab: ' +  str.expandtabs()
Defualt exapanded tab: this is string example!
>>> print 'Double exapanded tab: ' +  str.expandtabs(16)
Double exapanded tab: this is         string example!
"""
return ""
def find(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
"""
S.find(sub [,start [,end]]) -> int

检测字符串中是否包含子字符串str,如果指定beg(开始)和end(结束)范围,则检查是否包含在指定范围内,如果包含子字符串返回开始的索引值,否则返回-1;即str参数指定检索的字符串;beg参数指开始索引,默认为0;end参数指结束索引,默认为字符串的长度;
例如:
>>> str = 'this is string example!'
>>> str.find('ex')
15
>>> str.find('ex',10)
15
>>> str.find('ex',40)
-1
"""
return 0
def format(self, *args, **kwargs): # known special case of str.format
"""
S.format(*args, **kwargs) -> string

执行字符串格式化操作,替换字段使用{}分隔,替换字段可以是表示位置的位置或keyword参数名字;其中args指要替换的参数1,kwargs指要替换的参数2;
例如:
>>> '{0}, {1}, {2}'.format('a', 'b', 'c')
'a, b, c'
>>> '{}, {}, {}'.format('a', 'b', 'c')
'a, b, c'
>>> '{2}, {1}, {0}'.format('a', 'b', 'c')
'c, b, a'
>>> '{0}{1}{0}'.format('abra', 'cad')
'abracadabra'
>>> 'Coordinates: {latitude}, {longitude}'.format(latitude='37.24N', longitude='-115.81W')
'Coordinates: 37.24N, -115.81W'
>>> coord = {'latitude': '37.24N', 'longitude': '-115.81W'}
>>> 'Coordinates: {latitude}, {longitude}'.format(**coord)
'Coordinates: 37.24N, -115.81W'
>>> coord = (3, 5)
>>> 'X: {0[0]};  Y: {0[1]}'.format(coord)
'X: 3;  Y: 5'
>>> str = 'HOW {0} {1} WORKS'
>>> print(str.format("Python", 3))
HOW Python 3 WORKS
>>> str = 'HOW {soft} {Version} WORKS'
>>> print(str.format(soft = 'Python', Version = 2.7))
HOW Python 2.7 WORKS
"""
pass
def format_map(self, mapping): # real signature unknown; restored from __doc__
"""
S.format_map(mapping) -> str

执行字符串格式化操作,替换字段使用{}分隔,同str.format(**mapping), 除了直接使用mapping,而不复制到一个dict; (Python3新增)
例如:
>>> str = 'HOW {soft} {Version} WORKS'
>>> soft = 'Python'
>>> Version = 2.7
>>> print (str.format_map(vars()))
HOW Python 2.7 WORKS
"""
return ""
def index(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
"""
S.index(sub [,start [,end]]) -> int

检测字符串中是否包含子字符串str,如果指定beg(开始)和end(结束)范围,则检查是否包含在指定范围内,该方法与python find()方法一样,只不过如果str不在string中会报一个异常;即str参数指定检索的字符串;beg参数指开始索引,默认为0;end参数指结束索引,默认为字符串的长度;
例如:
>>> str = 'this is string example!'
>>> print str.index('ex')
15
>>> print str.index('ex',10)
15
>>> print str.index('ex',40)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: substring not found
"""
return 0
def isalnum(self): # real signature unknown; restored from __doc__
"""
S.isalnum() -> bool

检测字符串是否由字母和数字组成,返回布尔值;
例如:
>>> str = 'this2009'
>>> print str.isalnum()
True
>>> str = 'this is string example!'
>>> print str.isalnum()
False
"""
return False
def isalpha(self): # real signature unknown; restored from __doc__
"""
S.isalpha() -> bool

检测字符串是否只由字母组成,返回布尔值,所有字符都是字母则返回 True,否则返回 False;
例如:
>>> str = 'this2009'
>>> print str.isalpha()
False
>>> str = 'this is string example'
>>> print str.isalpha()
False
>>> str = 'this'
>>> print str.isalpha()
True
"""
return False
def isdecimal(self): # real signature unknown; restored from __doc__
"""
S.isdecimal() -> bool

检查字符串是否只包含十进制字符,这种方法只存在于unicode对象,返回布尔值,如果字符串是否只包含十进制字符返回True,否则返回False; (Python3新增)
注:定义一个十进制字符串,只需要在字符串前添加'u'前缀即可;
例如:
>>> str = u'this2009'
>>> print (str.isdecimal())
False
>>> str = u'22342009'
>>> print (str.isdecimal())
True
"""
return False
def isidentifier(self): # real signature unknown; restored from __doc__
"""
S.isidentifier() -> bool
判断字符串是否是合法的标识符,字符串仅包含中文字符合法,实际上这里判断的是变量名是否合法,返回布尔值; (Python3新增)
例如:
>>> str = 'Python3'
>>> print(str.isidentifier())
True
>>> str = '_123'
>>> print(str.isidentifier())
True
>>> str = '123'
>>> print(str.isidentifier())
False
>>> str = ''
>>> print(str.isidentifier())
False
>>> str = '123_'
>>> print(str.isidentifier())
False
>>> str = '#123'
>>> print(str.isidentifier())
False
>>> str = 'a123_'
>>> print(str.isidentifier())
True
>>> #123 = 'a'
...
>>> 123_ = 'a'
File "<stdin>", line 1
123_ = 'a'
^
SyntaxError: invalid token
"""
return False
def isdigit(self): # real signature unknown; restored from __doc__
"""
S.isdigit() -> bool

检测字符串是否只由数字组成,返回布尔值,如果字符串只包含数字则返回 True 否则返回 False;
例如:
>>> str = '123456'
>>> print str.isdigit()
True
>>> str = 'this is string example!'
>>> print str.isdigit()
False
"""
return False
def islower(self): # real signature unknown; restored from __doc__
"""
S.islower() -> bool

检测字符串是否由小写字母组成,返回布尔值,所有字符都是小写,则返回True,否则返回False;
例如:
>>> str = 'this is string example!'
>>> print str.islower()
True
>>> str = 'This is string example!'
>>> print str.islower()
False
"""
return False
def isnumeric(self): # real signature unknown; restored from __doc__
"""
S.isnumeric() -> bool

检测字符串是否只由数字组成,这种方法是只针对unicode对象,返回布尔值,如果字符串中只包含数字字符,则返回True,否则返回False; (Python3新增)
注:定义一个字符串为Unicode,只需要在字符串前添加'u'前缀即可;
例如:
>>> str = u'this2009'
>>> print (str.isnumeric())
False
>>> str = u'22342009'
>>> print (str.isnumeric())
True
"""
return False
def isprintable(self): # real signature unknown; restored from __doc__
"""
S.isprintable() -> bool

判断字符串的所有字符都是可打印字符或字符串为空,返回布尔值; (Python3新增)
例如:
>>> str = 'abc123'
>>> print (str.isprintable())
True
>>> str = '123\t'
>>> print (str.isprintable())
False
>>> str = ''
>>> print (str.isprintable())
True

"""
return False
def isspace(self): # real signature unknown; restored from __doc__
"""
S.isspace() -> bool

检测字符串是否只由空格组成,返回布尔值,字符串中只包含空格,则返回True,否则返回False;
例如:
>>> str = ' '
>>> print str.isspace()
True
>>> str = 'This is string example!'
>>> print str.isspace()
False
"""
return False
def istitle(self): # real signature unknown; restored from __doc__
"""
S.istitle() -> bool

检测字符串中所有的单词拼写首字母是否为大写,且其他字母为小写,返回布尔值,如果字符串中所有的单词拼写首字母是否为大写,且其他字母为小写则返回True,否则返回False;
例如:
>>> str = 'This Is String Example!'
>>> print (str.istitle())
True
>>> str = 'This Is String example!'
>>> print (str.istitle())
False
"""
return False
def isupper(self): # real signature unknown; restored from __doc__
"""
S.isupper() -> bool

检测字符串中所有的字母是否都为大写,返回布尔值,如果字符串中包含至少一个区分大小写的字符,并且所有这些(区分大小写的)字符都是大写,则返回True,否则返回False;
例如:
>>> str = 'THIS IS STRING EXAMPLE!'
>>> print (str.isupper())
True
>>> str = 'This Is String example!'
>>> print (str.istitle())
False
"""
return False
def join(self, iterable): # real signature unknown; restored from __doc__
"""
S.join(iterable) -> string

用于将序列中的元素以指定的字符连接生成一个新的字符串,其中sequence参数指要连接的元素序列;
例如:
>>> str1 = '-'
>>> str2 = ('a','b','c')
>>> print str1.join(str2)
a-b-c
"""
return ""
def ljust(self, width, fillchar=None): # real signature unknown; restored from __doc__
"""
S.ljust(width[, fillchar]) -> string

返回一个原字符串左对齐,并使用空格填充至指定长度的新字符串,如果指定的长度小于原字符串的长度则返回原字符串,其中width参数指指定字符串长度,fillchar参数指填充字符,默认为空格;
>>> str = 'This Is String example!'
>>> print str.ljust(50,'0')
This Is String example!000000000000000000000000000
"""
return ""
def lower(self): # real signature unknown; restored from __doc__
"""
S.lower() -> string

转换字符串中所有大写字符为小写,返回将字符串中所有大写字符转换为小写后生成的字符串;
例如:
>>> str = 'THIS IS STRING EXAMPLE!'
>>> print str.lower()
this is string example!
"""
return ""
def maketrans(self, *args, **kwargs): # real signature unknown
"""
Return a translation table usable for str.translate().

用于创建字符映射的转换表,并通过str.translate()进行返回,对于接受两个参数的最简单的调用方式,第一个参数是字符串,表示需要转换的字符,第二个参数也是字符串表示转换的目标;即intab参数指字符串中要替代的字符组成的字符串,outtab参数指相应的映射字符的字符串; (Python3新增)
注:两个字符串的长度必须相同,为一一对应的关系;
例如:
>>> str = 'this is string example!'
>>> intab = 'aeiou'
>>> outtab = '12345'
>>> tarn = str.maketrans(intab,outtab)
>>> print (str.translate(tarn))
th3s 3s str3ng 2x1mpl2!
>>> tarn = str.maketrans('aeiou','12345')
>>> print (str.translate(tarn))
th3s 3s str3ng 2x1mpl2!
"""
pass
def lstrip(self, chars=None): # real signature unknown; restored from __doc__
"""
S.lstrip([chars]) -> string or unicode

用于截掉字符串左边的空格或指定字符,返回截掉字符串左边的空格或指定字符后生成的新字符串,其中chars参数指指定截取的字符;
例如:
>>> str = '        This Is String example!'
>>> print str.lstrip()
This Is String example!
>>> str = '88888888This Is String example!88888888'
>>> print str.lstrip('8')
This Is String example!88888888
"""
return ""
def partition(self, sep): # real signature unknown; restored from __doc__
"""
S.partition(sep) -> (head, sep, tail)

用来根据指定的分隔符将字符串进行分割,如果字符串包含指定的分隔符,则返回一个3元的元组,第一个为分隔符左边的子串,第二个为分隔符本身,第三个为分隔符右边的子串;其中sep参数指指定的分隔符;
例如:
>>> str = 'http://434727.blog.51cto.com/'
>>> print str.partition('://')
('http', '://', '434727.blog.51cto.com/')
"""
pass
def replace(self, old, new, count=None): # real signature unknown; restored from __doc__
"""
S.replace(old, new[, count]) -> string

把字符串中的old(旧字符串)替换成new(新字符串),如果指定第三个参数count,则替换不超过count次;
>>> str = 'this is string example! this is really string'
>>> print str.replace('is', 'was')
thwas was string example! thwas was really string
>>> print str.replace('is', 'was',3)
thwas was string example! thwas is really string
"""
return ""
def rfind(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
"""
S.rfind(sub [,start [,end]]) -> int

返回字符串最后一次出现的位置,如果没有匹配项则返回-1,其中sub参数指查找的字符串;beg参数指开始查找的位置,默认为0;end参数指结束查找位置,默认为字符串的长度;
例如:
>>> str = 'this is string example!'
>>> print str.rfind('is')
5
>>> print str.rfind('is',0,10)
5
>>> print str.rfind('is',10,0)
-1
"""
return 0
def rindex(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
"""
S.rindex(sub [,start [,end]]) -> int

返回子字符串在字符串中最后出现的位置,如果没有匹配的字符串会报异常,其中sub参数指查找的字符串;beg参数指开始查找的位置,默认为0;end 参数指结束查找位置,默认为字符串的长度;
例如:
>>> str = 'this is string example!'
>>> print str.rindex('is')
5
>>> print str.rindex('is',0,10)
5
>>> print str.rindex('is',10,0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: substring not found
"""
return 0
def rjust(self, width, fillchar=None): # real signature unknown; restored from __doc__
"""
S.rjust(width[, fillchar]) -> string

返回一个原字符串右对齐,并使用空格填充至长度width的新字符串,如果指定的长度小于字符串的长度则返回原字符串;其中width参数指填充指定字符后中字符串的总长度;fillchar参数指填充的字符,默认为空格;
例如:
>>> str = 'this is string example!'
>>> print str.rjust(50,'0')
000000000000000000000000000this is string example!
"""
return ""
def rpartition(self, sep): # real signature unknown; restored from __doc__
"""
S.rpartition(sep) -> (head, sep, tail)

从后往前查找,返回包含字符串中分隔符之前、分隔符、分隔符之后的子字符串的元组;如果没找到分隔符,返回字符串和两个空字符串;
例如:
>>> str = 'this is string example!'
>>> print str.rpartition('st')
('this is ', 'st', 'ring example!')
>>> print str.rpartition('is')
('this ', 'is', ' string example!')
>>> print str.rpartition('py')
('', '', 'this is string example!')
"""
pass
def rsplit(self, sep=None, maxsplit=None): # real signature unknown; restored from __doc__
"""
S.rsplit([sep [,maxsplit]]) -> list of strings

从后往前按照指定的分隔符对字符串进行切片,返回一个列表,其中sep参数指分隔符,默认为空格;maxsplit参数指最多分拆次数;
例如:
>>> str = 'this is string example!'
>>> print str.rsplit()
['this', 'is', 'string', 'example!']
>>> print str.rsplit('st')
['this is ', 'ring example!']
>>> print str.rsplit('is')
['th', ' ', ' string example!']
>>> print str.rsplit('is',1)
['this ', ' string example!']
"""
return []
def rstrip(self, chars=None): # real signature unknown; restored from __doc__
"""
S.rstrip([chars]) -> string or unicode

删除string字符串末尾的指定字符(默认为空格),返回删除string字符串末尾的指定字符后生成的新字符串,其中chars参数指删除的字符(默认为空格);
例如:
>>> str = '     this is string example!     '
>>> print str.rstrip()
this is string example!
>>> str = '88888888this is string example!88888888'
>>> print str.rstrip('8')
88888888this is string example!
"""
return ""
def split(self, sep=None, maxsplit=None): # real signature unknown; restored from __doc__
"""
S.split([sep [,maxsplit]]) -> list of strings

通过指定分隔符对字符串进行切片,如果参数maxsplit有指定值,则仅分隔maxsplit个子字符串;其中sep参数指分隔符,默认为所有的空字符,包括空格、换行(\n)、制表符(\t)等;maxsplit参数指分割次数;
例如:
>>> str = 'Line1-abcdef \nLine2-abc \nLine4-abcd'
>>> print str.split()
['Line1-abcdef', 'Line2-abc', 'Line4-abcd']
>>> print str.split(' ',1)
['Line1-abcdef', '\nLine2-abc \nLine4-abcd']
"""
return []
def splitlines(self, keepends=False): # real signature unknown; restored from __doc__
"""
S.splitlines(keepends=False) -> list of strings

按照行('\r', '\r\n', \n')分隔,返回一个包含各行作为元素的列表,如果参数keepends为 False,不包含换行符,如果为True,则保留换行符,返回一个包含各行作为元素的列表;其中keepends参数指在输出结果里是否去掉换行符('\r', '\r\n', \n'),默认为 False,不包含换行符,如果为 True,则保留换行符;
例如:
>>> str1 = 'ab c\n\nde fg\rkl\r\n'
>>> print str1.splitlines()
['ab c', '', 'de fg', 'kl']
>>> str2 = 'ab c\n\nde fg\rkl\r\n'
>>> print str2.splitlines(True)
['ab c\n', '\n', 'de fg\r', 'kl\r\n']
"""
return []
def startswith(self, prefix, start=None, end=None): # real signature unknown; restored from __doc__
"""
S.startswith(prefix[, start[, end]]) -> bool

用于检查字符串是否是以指定子字符串开头,如果是则返回True,否则返回False,如果参数beg和end指定了值,则在指定范围内检查;其中prefix参数指检测的字符串;start参数用于设置字符串检测的起始位置;end参数用于设置字符串检测的结束位置;
例如:
>>> str = 'this is string example!'
>>> print str.startswith('this')
True
>>> print str.startswith('is',2,4)
True
>>> print str.startswith('this',2,4)
False
"""
return False
def strip(self, chars=None): # real signature unknown; restored from __doc__
"""
S.strip([chars]) -> string or unicode

用于移除字符串头尾指定的字符(默认为空格),返回移除字符串头尾指定的字符生成的新字符串;其中chars参数指移除字符串头尾指定的字符;
例如:
>>> str = '88888888this is string example!88888888'
>>> print str.strip('8')
this is string example!
"""
return ""
def swapcase(self): # real signature unknown; restored from __doc__
"""
S.swapcase() -> string

用于对字符串的大小写字母进行转换,返回大小写字母转换后生成的新字符串;
例如:
>>> str = 'this is string example!'
>>> print str.swapcase()
THIS IS STRING EXAMPLE!
"""
return ""
def title(self): # real signature unknown; restored from __doc__
"""
S.title() -> string

返回"标题化"的字符串,就是说所有单词都是以大写开始,其余字母均为小写;
例如:
>>> str = 'this is string example!'
>>> print str.title()
This Is String Example!
"""
return ""
def translate(self, table, deletechars=None): # real signature unknown; restored from __doc__
"""
S.translate(table [,deletechars]) -> string

根据参数table给出的表(包含256个字符)转换字符串的字符, 要过滤掉的字符放到del参数中,返回翻译后的字符串;其中table参数指翻译表,翻译表是通过maketrans方法转换而来;deletechars参数指字符串中要过滤的字符列表;
例如:
>>> str = 'this is string example!'
>>> intab = 'aeiou'
>>> outtab = '12345'
>>> tarn = str.maketrans(intab,outtab)
>>> print (str.translate(tarn))
th3s 3s str3ng 2x1mpl2!
>>> tarn = str.maketrans('aeiou','12345')
>>> print (str.translate(tarn))
th3s 3s str3ng 2x1mpl2!
"""
return ""
def upper(self): # real signature unknown; restored from __doc__
"""
S.upper() -> string

将字符串中的小写字母转为大写字母,返回小写字母转为大写字母的字符串;
例如:
>>> str = 'this is string example!'
>>> print str.upper()
THIS IS STRING EXAMPLE!
"""
return ""
def zfill(self, width): # real signature unknown; restored from __doc__
"""
S.zfill(width) -> string

返回指定长度的字符串,原字符串右对齐,前面填充0,即width参数指定字符串的长度。原字符串右对齐,前面填充0;
例如:
>>> str = 'this is string example!'
>>> print str.zfill(40)
00000000000000000this is string example!
"""
return ""
def _formatter_field_name_split(self, *args, **kwargs): # real signature unknown
"""
(Python2特有,Python3已删除)
"""
pass
def _formatter_parser(self, *args, **kwargs): # real signature unknown
"""
(Python2特有,Python3已删除)
"""
pass
def __add__(self, y): # real signature unknown; restored from __doc__
"""
x.__add__(y) 等同于 x+y

将两个字符串相加,返回新的字符串;
例如:
>>> x = 'a'
>>> y = 'b'
>>> x.__add__(y)
'ab'
>>> x + y
'ab'
"""
pass
def __contains__(self, y): # real signature unknown; restored from __doc__
"""
x.__contains__(y) 等同于 y in x

字符串包含判断,即判断y是否包含在x中,返回布尔值;
例如:
>>> x = 'a'
>>> y = 'b'
>>> y in x
False
>>> x = 'ab'
>>> y in x
True
"""
pass
def __eq__(self, y): # real signature unknown; restored from __doc__
"""
x.__eq__(y) 等同于 x==y

字符串等同于判断,即判断x是否等于y,返回布尔值;
例如:
>>> x = 'a'
>>> y = 'b'
>>> x == y
False
>>> y = 'a'
>>> x == y
True
"""
pass
def __format__(self, format_spec): # real signature unknown; restored from __doc__
"""
S.__format__(format_spec) -> string

格式化为字符串;
"""
return ""
def __getattribute__(self, name): # real signature unknown; restored from __doc__
"""
x.__getattribute__('name') 等同于 x.name
"""
pass
def __getitem__(self, y): # real signature unknown; restored from __doc__
"""
x.__getitem__(y) 等同于 x[y]

返回字符串指定下标的子字符串,下标值需指定并为整数型,否则报错;
例如:
>>> x = 'abc'
>>> y = 1
>>> x.__getitem__(y)
'b'
>>> x[y]
'b'
>>> x.__getitem__()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: expected 1 arguments, got 0
>>> x.__getitem__(1.1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: string indices must be integers, not float
"""
pass
def __getnewargs__(self, *args, **kwargs): # real signature unknown
pass
def __getslice__(self, i, j): # real signature unknown; restored from __doc__
"""
x.__getslice__(i, j) 等同于 x[i:j]

返回字符串指定范围的子字符串,i参数指开始位置,j参数指结束位置,i,j两个参数必须同时存在,不指定或缺少参数将报错;(Python2特有,Python3已删除)
例如:
>>> x = 'abcdefg'
>>> x.__getslice__(1,4)
'bcd'
>>> x.__getslice__(1,0)
''
>>> x.__getslice__()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: function takes exactly 2 arguments (0 given)
>>> x.__getslice__(1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: function takes exactly 2 arguments (1 given)
>>> x[1:4]
'bcd'
"""
pass
def __ge__(self, y): # real signature unknown; restored from __doc__
"""
x.__ge__(y) 等同于 x>=y

字符串大小等于判断,返回布尔值;
例如:
>>> x = 'abc'
>>> y = 'ab'
>>> x >= y
True
>>> y = 'abcd'
>>> x >= y
False
"""
pass
def __gt__(self, y): # real signature unknown; restored from __doc__
"""
x.__gt__(y) 等于 x>y

字符串大于判断,返回布尔值;
例如:
>>> x = 'abc'
>>> y = 'ab'
>>> x > y
True
>>> y = 'abcd'
>>> x > y
False
"""
pass
def __hash__(self): # real signature unknown; restored from __doc__
"""
x.__hash__() 等同于 hash(x)

返回字符串的哈希值;
例如:
>>> x = 'abcd'
>>> x.__hash__()
1540938112
>>> hash(x)
1540938112
"""
pass
def __init__(self, string=''): # known special case of str.__init__
"""
str(object='') -> string

构造方法,执行x = 'abc'时自动调用str函数;
"""
pass
def __len__(self): # real signature unknown; restored from __doc__
"""
x.__len__() 等同于 len(x)

返回字符串的长度;
例如:
>>> x = 'abcd'
>>> x.__len__()
4
>>> len(x)
4
"""
pass
def __iter__(self, *args, **kwargs): # real signature unknown
"""
迭代对象,返回自己; (Python3新增)
"""
pass
def __le__(self, y): # real signature unknown; restored from __doc__
"""
x.__le__(y) 等同于 x<=y

字符串小于等于判断,返回布尔值;
例如:
>>> x = 'abc'
>>> y = 'abcdef'
>>> x .__le__(y)
True
>>> x <= y
True
>>> y = 'ab'
>>> x <= y
False
"""
pass
def __lt__(self, y): # real signature unknown; restored from __doc__
"""
x.__lt__(y) 等同于 x<y

字符串小于判断,返回布尔值;
>>> x = 'abc'
>>> y = 'abcdef'
>>> x .__lt__(y)
True
>>> x < y
True
>>> y = 'ab'
>>> x < y
False
"""
pass
def __mod__(self, y): # real signature unknown; restored from __doc__
"""
x.__mod__(y) 等同于 x%y
"""
pass
def __mul__(self, n): # real signature unknown; restored from __doc__
"""
x.__mul__(n) 等同于 x*n

字符串乘法,n需为整数,相当于n个字符串相加,新加入的字符串位置在原字符串后;
例如:
>>> x = 'abc'
>>> n = 2
>>> x.__mul__(n)
'abcabc'
>>> x * n
'abcabc'
"""
pass
@staticmethod # known case of __new__
def __new__(S, *more): # real signature unknown; restored from __doc__
"""
T.__new__(S, ...) -> a new object with type S, a subtype of T
"""
pass
def __ne__(self, y): # real signature unknown; restored from __doc__
"""
x.__ne__(y) 等同于 x!=y

字符串不等于判断,返回布尔值;

"""
pass
def __repr__(self): # real signature unknown; restored from __doc__
"""
x.__repr__() 等同于 repr(x)

转化为解释器可读取的形式,会使用""号将字符串包含起来;
例如:
>>> x = 'abcd'
>>> x.__repr__()
"'abcd'"
>>> repr(x)
"'abcd'"
"""
pass
def __rmod__(self, y): # real signature unknown; restored from __doc__
"""
x.__rmod__(y) 等同于 y%x
"""
pass
def __rmul__(self, n): # real signature unknown; restored from __doc__
"""
x.__rmul__(n) 等同于 n*x

字符串乘法,n需为整数,相当于n个字符串相加,新加入的字符串位置在原字符串前;;
"""
pass
def __sizeof__(self): # real signature unknown; restored from __doc__
"""
S.__sizeof__() -> size of S in memory, in bytes

返回内存中的大小(以字节为单位);
"""
pass
def __str__(self): # real signature unknown; restored from __doc__
"""
x.__str__() <==> str(x)

转换为人阅读的形式,如果没有适于人阅读的解释形式的话,则返回解释器课阅读的形式;
"""
pass
二、list的函数说明
列表可以完成大多数集合类的数据结构实现,列表中元素的类型可以不相同,它支持数字,字符串甚至可以包含列表(所谓嵌套);列表是写在方括号([])之间、用逗号分隔开的元素列表;和字符串一样,列表同样可以被索引和截取,列表被截取后返回一个包含所需元素的新列表;
在python中列表提供的函数具体如下:
class list(object):
"""
list() -> 新的空列表;
list(iterable) -> 从iterable参数中获取值初始化成新的列表;
"""
def append(self, p_object): # real signature unknown; restored from __doc__
"""
L.append(object)

用于在列表末尾添加新的对象,该方法无返回值,但是会修改原来的列表;其中self参数指添加到列表末尾的对象;
例如:
>>> alist = [123, 'xyz', 'zara', 'abc']
>>> alist.append( 2009 )
>>> alist
[123, 'xyz', 'zara', 'abc', 2009]
"""
pass
def clear(self): # real signature unknown; restored from __doc__
"""
L.clear() -> None

清空列表; (Python3新增)
例如:
>>> alist = [11,22,33,44]
>>> alist
[11, 22, 33, 44]
>>> alist.clear()
>>> alist
[]
"""
pass

def copy(self): # real signature unknown; restored from __doc__
"""
L.copy() -> list

拷贝一个列表,此处是浅拷贝; (Python3新增)
例如:
>>> alist1 = [11,22,33,44]
>>> alist2 = alist.copy()
>>> alist2
[11, 22, 33, 44]
"""
return []
def count(self, value): # real signature unknown; restored from __doc__
"""
L.count(value) -> integer

用于统计某个元素在列表中出现的次数,返回整形,其中obj参数指列表中统计的对象;
例如:
>>> alist = [123, 'xyz', 'zara', 'abc', 123]
>>> print 'Count for 123 : ', alist.count(123)
Count for 123 :  2
>>> print 'Count for zara : ', alist.count('zara')
Count for zara :  1
"""
return 0
def extend(self, iterable): # real signature unknown; restored from __doc__
"""
L.extend(iterable) -- extend

用于在列表末尾一次性追加另一个序列中的多个值(用新列表扩展原来的列表),该方法没有返回值,但会在已存在的列表中添加新的列表内容;其中iterable参数指元素列表;
例如:
>>> alist = [123, 'xyz', 'zara', 'abc']
>>> blist = [2009, 'manni']
>>> alist.extend(blist)
>>> alist
[123, 'xyz', 'zara', 'abc', 2009, 'manni']
"""
pass
def index(self, value, start=None, stop=None): # real signature unknown; restored from __doc__
"""
L.index(value, [start, [stop]]) -> integer

用于从列表中找出某个值第一个匹配项的索引位置,该方法返回查找对象的索引位置,如果没有找到对象则抛出异常;其中value参数指检索的字符串,start参数指检索的起始位置,stop参数指检索的结束位置;
例如:
>>> alist = [123, 'xyz', 'zara', 'abc']
>>> alist.index('xyz')
1
>>> alist.index('zara',1)
2
>>> alist.index('zara',1,5)
2
>>> alist.index('zara',1,0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: 'zara' is not in list
"""
return 0
def insert(self, index, p_object): # real signature unknown; restored from __doc__
"""
L.insert(index, object)

用于将指定对象插入列表的指定位置,该方法没有返回值,会直接修改原有列表,其中index参数指插入的位置,object参数指插入的字符串,两个参数需同时指定;
例如:
>>> alist = [123, 'xyz', 'zara', 'abc']
>>> alist
[123, 'def', 'xyz', 'zara', 'abc']
>>> alist.insert('def')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: insert() takes exactly 2 arguments (1 given)
>>> alist.insert(1,'def')
>>> alist.insert(2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: insert() takes exactly 2 arguments (1 given)
"""
pass
def pop(self, index=None): # real signature unknown; restored from __doc__
"""
L.pop([index]) -> item

用于移除列表中的一个元素(默认最后一个元素),并且返回该元素的值,如果列表为空或索引超出范围,则引报错;
例如:
>>> alist = [123, 'xyz', 'zara', 'abc']
>>> alist.pop()
'abc'
>>> alist
[123, 'xyz', 'zara']
>>> alist.pop(2)
'zara'
>>> alist
[123, 'xyz']
>>> alist.pop(123)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: pop index out of range
>>> alist = []
>>> alist.pop()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: pop from empty list
"""
pass
def remove(self, value): # real signature unknown; restored from __doc__
"""
L.remove(value)

用于移除列表中某个值的第一个匹配项,该方法没有返回值但是会移除两种中的某个值的第一个匹配项;
例如:
>>> alist = [123, 'xyz', 'zara', 'abc','xyz']
>>> alist.remove('xyz')
>>> alist
[123, 'zara', 'abc', 'xyz']
"""
pass
def reverse(self): # real signature unknown; restored from __doc__
"""
L.reverse()

用于反向列表中元素,该方法没有返回值,但是会对列表的元素进行反向排序;
例如:
>>> alist = [123, 'xyz', 'zara', 'abc']
>>> alist.reverse()
>>> alist
['abc', 'zara', 'xyz', 123]
"""
pass
def sort(self, cmp=None, key=None, reverse=False): # real signature unknown; restored from __doc__
"""
L.sort(cmp=None, key=None, reverse=False)

用于对原列表进行排序,如果指定参数,则使用会使用该参数的方法进行排序,该方法没有返回值,但是会对列表的对象进行排序;
例如:
>>> alist = [123, 'xyz', 'zara', 'abc']
>>> alist.sort()
>>> alist
[123, 'abc', 'xyz', 'zara']
>>> alist.sort(reverse=True)
>>> alist
['zara', 'xyz', 'abc', 123]
"""
pass
def __add__(self, y): # real signature unknown; restored from __doc__
"""
x.__add__(y) 等同于 x+y

加法,将两个列表值进行相加,并返回新的列表值;
例如:
>>> alist = [123, 'xyz', 'zara', 'abc']
>>> blist = [456, 'wsx', 'edc']
>>> alist.__add__(blist)
[123, 'xyz', 'zara', 'abc', 456, 'wsx', 'edc']
>>> alist + blist
[123, 'xyz', 'zara', 'abc', 456, 'wsx', 'edc']
"""
pass
def __contains__(self, y): # real signature unknown; restored from __doc__
"""
x.__contains__(y) 等同于 y in x

列表包含判断,即判断y是否包含在x中,返回布尔值;
例如:
>>> x = [ 11, 22, 33, 44 ]
>>> y = 11
>>> x.__contains__(y)
True
>>> y in x
True
>>> y = 55
>>> x.__contains__(y)
False
>>> x = [ 11,[ 22, 33], 44]
>>> y = [ 22, 33 ]
>>> x.__contains__(y)
True
"""
pass
def __delitem__(self, y): # real signature unknown; restored from __doc__
"""
x.__delitem__(y) 等同于 del x[y]

用于移除列表中指定下标的一个元素,该方法没有返回值,如果列表为空或索引超出范围,则引报错;
例如:
>>> x = [11,22,33,44]
>>> y = 2
>>> x.__delitem__(y)
>>> x
[11, 22, 44]
>>> del x[y]
>>> x
[11, 22]
>>> x = []
>>> del x[y]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: list assignment index out of range
>>> y = 10
>>> del x[y]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: list assignment index out of range
"""
pass
def __delslice__(self, i, j): # real signature unknown; restored from __doc__
"""
x.__delslice__(i, j) 等同于 del x[i:j]

用于移除列表中指定下标范围的元素,该方法没有返回值,i参数指开始位置,j参数指结束位置,i,j两个参数必须同时存在,不指定或缺少参数将报错;(Python2特有,Python3已删除)
例如:
>>> x = [11,22,33,44,55]
>>> x.__delslice__(1,3)
>>> x
[11, 44, 55]
>>> x.__delslice__(4,5)
>>> x
[11, 44, 55]
"""
pass
def __eq__(self, y): # real signature unknown; restored from __doc__
"""
x.__eq__(y) 等同于 x==y

列表等同于判断,即判断x是否等于y,返回布尔值;
例如:
>>> x = [11,22,33,44,55]
>>> y = [66,77]
>>> x.__eq__(y)
False
>>> x == y
False
>>> y = [11,22,33,44,55]
>>> x == y
True
"""
pass
def __getattribute__(self, name): # real signature unknown; restored from __doc__
"""
x.__getattribute__('name') 等同于 x.name
"""
pass
def __getitem__(self, y): # real signature unknown; restored from __doc__
"""
x.__getitem__(y) 等同于 x[y]

返回列表指定下标的子字符串,并返回子字符串,下标值需指定并为整数型,否则报错;
例如:
>>> x = [11,22,33,44,55]
>>> x.__getitem__(1)
22
"""
pass
def __getslice__(self, i, j): # real signature unknown; restored from __doc__
"""
x.__getslice__(i, j) 等同于 x[i:j]

返回列表指定范围的子列表,i参数指开始位置,j参数指结束位置,i,j两个参数必须同时存在,不指定或缺少参数将报错;(Python2特有,Python3已删除)
例如:
>>> x = [11,22,33,44,55]
>>> x.__getslice__(1,4)
[22, 33, 44]
>>> x
[11, 22, 33, 44, 55]
>>> x[1:4]
[22, 33, 44]
"""
pass
def __ge__(self, y): # real signature unknown; restored from __doc__
"""
x.__ge__(y) 等同于 x>=y

列表大小等于判断,返回布尔值;
例如:
>>> x = [11,22,33,44,55]
>>> y = [11,22]
>>> x.__ge__(y)
True
>>> x >= y
True
>>> y = [11,22,33,44,55]
>>> x >= y
True
>>> y = [11,22,33,44,55,66]
>>> x >= y
False
"""
pass
def __gt__(self, y): # real signature unknown; restored from __doc__
"""
x.__gt__(y) 等同于 x>y

列表大于判断,返回布尔值;
例如:
>>> x = [11,22,33,44,55]
>>> y = [11,22,33,44]
>>> x.__gt__(y)
True
>>> x > y
True
>>> y = [11,22,33,44,55,66]
>>> x > y
False
"""
pass
def __iadd__(self, y): # real signature unknown; restored from __doc__
"""
x.__iadd__(y) 等同于 x+=y

将第二个个列表加入到第一个列表,即将y的列表值加入x列表,使用x.__iadd__(y)方法会返回改变后的列表,使用x += y只会改变列表不会有返回值;
例如:
>>> x = [11,22,33,44]
>>> y = [55,66]
>>> x.__iadd__(y)
[11, 22, 33, 44, 55, 66]
>>> x
[11, 22, 33, 44, 55, 66]
>>> x += y
>>> x
[11, 22, 33, 44, 55, 66, 55, 66]
"""
pass
def __imul__(self, y): # real signature unknown; restored from __doc__
"""
x.__imul__(y) 等同于 x*=y

列表乘法,y需为整数,相当于y个列表进行相加,并改变原有列表;使用x.__imul__(y)方法会返回改变后的列表,使用x *= y只会改变列表不会有返回值;
例如:
>>> x = [11,22,33,44]
>>> x.__imul__(2)
[11, 22, 33, 44, 11, 22, 33, 44]
>>> x
[11, 22, 33, 44, 11, 22, 33, 44]
>>> x *= 2
>>> x
[11, 22, 33, 44, 11, 22, 33, 44, 11, 22, 33, 44, 11, 22, 33, 44]
"""
pass
def __init__(self, seq=()): # known special case of list.__init__
"""
list() -> new empty list
list(iterable) -> new list initialized from iterable's items

构造方法,执行x = []时自动调用list函数;
"""
pass
def __iter__(self): # real signature unknown; restored from __doc__
"""
x.__iter__() 等同于 iter(x)

迭代对象,返回自己;
"""
pass
def __len__(self): # real signature unknown; restored from __doc__
"""
x.__len__() 等同于 len(x)

返回列表的长度;
例如:
>>> x = [11,22,33,44]
>>> x.__len__()
4
>>> len(x)
4
"""
pass
def __le__(self, y): # real signature unknown; restored from __doc__
"""
x.__le__(y) 等同于 x<=y

列表小于等于判断,返回布尔值;
"""
pass
def __lt__(self, y): # real signature unknown; restored from __doc__
"""
x.__lt__(y) 等同于 x<y
列表小于判断,返回布尔值;
"""
pass
def __mul__(self, n): # real signature unknown; restored from __doc__
"""
x.__mul__(n) 等同于 x*n

列表乘法,n需为整数,相当于n个字符串相加,新加入的字符串位置在原字符串后,不会改变原有列表;
例如:
>>> x = [11,22,33,44]
>>> x.__mul__(2)
[11, 22, 33, 44, 11, 22, 33, 44]
>>> x
[11, 22, 33, 44]
>>> x * 2
[11, 22, 33, 44, 11, 22, 33, 44]
>>> x
[11, 22, 33, 44]
"""
pass
@staticmethod # known case of __new__
def __new__(S, *more): # real signature unknown; restored from __doc__
"""
T.__new__(S, ...) -> a new object with type S, a subtype of T
"""
pass
def __ne__(self, y): # real signature unknown; restored from __doc__
"""
x.__ne__(y) 等同于 x!=y

字符串不等于判断,返回布尔值;
"""
pass
def __repr__(self): # real signature unknown; restored from __doc__
"""
x.__repr__() 等同于 repr(x)

转化为解释器可读取的形式,即转换为字符串格式;
"""
pass
def __reversed__(self): # real signature unknown; restored from __doc__
"""
L.__reversed__() -- return a reverse iterator over the list

返回一个反向迭代器;
"""
pass
def __rmul__(self, n): # real signature unknown; restored from __doc__
"""
x.__rmul__(n) 等同于 n*x

字符串乘法,n需为整数,相当于n个字符串相加,新加入的字符串位置在原字符串前;
"""
pass
def __setitem__(self, i, y): # real signature unknown; restored from __doc__
"""
x.__setitem__(i, y) 等同于 x[i]=y

将x列表指定的i下标值替换为y,该方法直接改变x列表,但没有返回值,
例如:
>>> x = [11,22,33,44]
>>> y = []
>>> x.__setitem__(2,y)
>>> x
[11, 22, [], 44]
>>> y = [55,66]
>>> x[2]= y
>>> x
[11, 22, [55, 66], 44]
"""
pass
def __setslice__(self, i, j, y): # real signature unknown; restored from __doc__
"""
x.__setslice__(i, j, y) 等同于 x[i:j]=y

将x列表指定下标范围对应的值,修改为y,i参数指开始位置,j参数指结束位置,i,j两个参数必须同时存在,不指定或缺少参数将报错;(Python2特有,Python3已删除)
例如:
>>> x = [11,22,33,44,55,66]
>>> y = [99,100]
>>> x.__setslice__(1,4,y)
>>> x
[11, 99, 100, 55, 66]
>>> x = [11,22,33,44,55,66]
>>> x[0:3] = y
>>> x
[99, 100, 44, 55, 66]
>>> x = [11,22,33,44,55,66]
>>> x[0:0] = y
>>> x
[99, 100, 11, 22, 33, 44, 55, 66]
"""
pass
def __sizeof__(self): # real signature unknown; restored from __doc__
"""
L.__sizeof__() -- size of L in memory, in bytes

返回内存中的大小(以字节为单位);
"""
pass
__hash__ = None
三、元组的函数说明(元组相当于不能修改的列表,其只有只读属性没有修改的属性,使用方法与list函数一致)
元组(tuple)与列表类似,不同之处在于元组的元素不能修改,元组写在小括号(())里,元素之间用逗号隔开;
在python中元组提供的函数如下:
class tuple(object):
"""
tuple() -> empty tuple
tuple(iterable) -> tuple initialized from iterable's items

If the argument is a tuple, the return value is the same object.
"""
def count(self, value): # real signature unknown; restored from __doc__
""" T.count(value) -> integer -- return number of occurrences of value """
return 0
def index(self, value, start=None, stop=None): # real signature unknown; restored from __doc__
"""
T.index(value, [start, [stop]]) -> integer -- return first index of value.
Raises ValueError if the value is not present.
"""
return 0
def __add__(self, y): # real signature unknown; restored from __doc__
""" x.__add__(y) <==> x+y """
pass
def __contains__(self, y): # real signature unknown; restored from __doc__
""" x.__contains__(y) <==> y in x """
pass
def __eq__(self, y): # real signature unknown; restored from __doc__
""" x.__eq__(y) <==> x==y """
pass
def __getattribute__(self, name): # real signature unknown; restored from __doc__
""" x.__getattribute__('name') <==> x.name """
pass
def __getitem__(self, y): # real signature unknown; restored from __doc__
""" x.__getitem__(y) <==> x[y] """
pass
def __getnewargs__(self, *args, **kwargs): # real signature unknown
pass
def __getslice__(self, i, j): # real signature unknown; restored from __doc__
"""
x.__getslice__(i, j) <==> x[i:j]

Use of negative indices is not supported. (Python2特有,Python3已删除)
"""
pass
def __ge__(self, y): # real signature unknown; restored from __doc__
""" x.__ge__(y) <==> x>=y """
pass
def __gt__(self, y): # real signature unknown; restored from __doc__
""" x.__gt__(y) <==> x>y """
pass
def __hash__(self): # real signature unknown; restored from __doc__
""" x.__hash__() <==> hash(x) """
pass
def __init__(self, seq=()): # known special case of tuple.__init__
"""
tuple() -> empty tuple
tuple(iterable) -> tuple initialized from iterable's items

If the argument is a tuple, the return value is the same object.
# (copied from class doc)
"""
pass
def __iter__(self): # real signature unknown; restored from __doc__
""" x.__iter__() <==> iter(x) """
pass
def __len__(self): # real signature unknown; restored from __doc__
""" x.__len__() <==> len(x) """
pass
def __le__(self, y): # real signature unknown; restored from __doc__
""" x.__le__(y) <==> x<=y """
pass
def __lt__(self, y): # real signature unknown; restored from __doc__
""" x.__lt__(y) <==> x<y """
pass
def __mul__(self, n): # real signature unknown; restored from __doc__
""" x.__mul__(n) <==> x*n """
pass
@staticmethod # known case of __new__
def __new__(S, *more): # real signature unknown; restored from __doc__
""" T.__new__(S, ...) -> a new object with type S, a subtype of T """
pass
def __ne__(self, y): # real signature unknown; restored from __doc__
""" x.__ne__(y) <==> x!=y """
pass
def __repr__(self): # real signature unknown; restored from __doc__
""" x.__repr__() <==> repr(x) """
pass
def __rmul__(self, n): # real signature unknown; restored from __doc__
""" x.__rmul__(n) <==> n*x """
pass
四、字典的函数说明
字典(dictionary)是Python中另一个非常有用的内置数据类型,列表是有序的对象结合,字典是无序的对象集合,两者之间的区别在于:字典当中的元素是通过键来存取的,而不是通过偏移存取;
字典是一种映射类型,字典用"{ }"标识,它是一个无序的键(key) : 值(value)对集合,键(key)必须使用不可变类型,在同一个字典中,键(key)必须是唯一的;
python中字典提供的函数如下:
class dict(object):
"""
dict() -> 新的空字典
dict(mapping) -> 从(key, value)获取值,并初始化的新字典;
dict(iterable) -> 也可通过以下方法初始化新字典:
d = {}
for k, v in iterable:
d[k] = v
dict(**kwargs) -> 使用name=value方法初始化新字典;
For example:  dict(one=1, two=2)
"""
def clear(self): # real signature unknown; restored from __doc__
"""
D.clear() -> None.
清空字典;
例如:
>>> x = { 'k1':'v1','k2':'v2' }
>>> x.clear()
>>> x
{}
"""
pass
def copy(self): # real signature unknown; restored from __doc__
"""
D.copy() -> a shallow copy of D

拷贝一个字典,此处是浅拷贝;
例如:
>>> x = { 'k1':'v1','k2':'v2' }
>>> y = x.copy()
>>> y
{'k2': 'v2', 'k1': 'v1'}
"""
pass
@staticmethod # known case
def fromkeys(S, v=None): # real signature unknown; restored from __doc__
"""
dict.fromkeys(S[,v]) -> New dict with keys from S and values equal to v.
v defaults to None.

创建并返回一个新字典,以S中的元素做该字典的键,v做该字典中所有键对应的初始值(默认为None);
例如:
>>> x = [ 'k1','k2','k3']
>>> y = {}
>>> y.fromkeys(x,'v1')
{'k3': 'v1', 'k2': 'v1', 'k1': 'v1'}
>>> y
{}
"""
pass
def get(self, k, d=None): # real signature unknown; restored from __doc__
"""
D.get(k[,d]) -> D[k] if k in D, else d.  d defaults to None.

返回字典中key对应的值,若key不存在字典中,则返回default的值(default默认为None)
例如:
>>> x = { 'k1':'v1','k2':'v2' }
>>> y = x.get('k2')
>>> y
'v2'
>>> y = x.get('k3','v3')
>>> y
'v3'
"""
pass
def has_key(self, k): # real signature unknown; restored from __doc__
"""
D.has_key(k) -> True if D has a key k, else False

检查字典是否存在指定的key; (Python2特有,Python3已删除)
例如:
>>> x = { 'k1':'v1','k2':'v2' }
>>> x.has_key('k1')
True
>>> x.has_key('v1')
False
>>> x.has_key('k3')
False
"""
return False
def items(self): # real signature unknown; restored from __doc__
"""
D.items() -> list of D's (key, value) pairs, as 2-tuples

返回一个包含所有(key, value)元祖的列表;

例如:
>>> x = { 'k1':'v1','k2':'v2' }
>>> y = x.items()
>>> y
[('k2', 'v2'), ('k1', 'v1')]
"""
return []
def iteritems(self): # real signature unknown; restored from __doc__
"""
D.iteritems() -> an iterator over the (key, value) items of D

字典项可迭代,方法在需要迭代结果的时候使用最适合,而且它的工作效率非常的高; (Python2特有,Python3已删除)
例如:
>>> x = { 'k1':'v1','k2':'v2' }
>>> y = x.iteritems()
>>> y
<dictionary-itemiterator object at 0x02B0EEA0>
>>> type(y)
<type 'dictionary-itemiterator'>
>>> list(y)
[('k2', 'v2'), ('k1', 'v1')]
"""
pass
def iterkeys(self): # real signature unknown; restored from __doc__
"""
D.iterkeys() -> an iterator over the keys of D

key可迭代; (Python2特有,Python3已删除)
例如:
>>> x = { 'k1':'v1','k2':'v2' }
>>> y = x.iterkeys()
>>> y
<dictionary-keyiterator object at 0x030CACF0>
>>> type(y)
<type 'dictionary-keyiterator'>
>>> list(y)
['k2', 'k1']
"""
pass
def itervalues(self): # real signature unknown; restored from __doc__
"""
D.itervalues() -> an iterator over the values of D

value可迭代; (Python2特有,Python3已删除)
例如:
>>> x = { 'k1':'v1','k2':'v2' }
>>> y = x.itervalues()
>>> y
<dictionary-valueiterator object at 0x031096F0>
>>> type(y)
<type 'dictionary-valueiterator'>
>>> list(y)
['v2', 'v1']
"""
pass
def keys(self): # real signature unknown; restored from __doc__
"""
D.keys() -> list of D's keys

返回一个包含字典所有key的列表;
例如:
>>> x = { 'k1':'v1','k2':'v2' }
>>> x.keys()
['k2', 'k1']
"""
return []
def pop(self, k, d=None): # real signature unknown; restored from __doc__
"""
D.pop(k[,d]) -> v

弹出指定key值的元素(因为字典是无序的,所以必须指定key值),会改变原有字典,并返回弹出key的value,如果key不存在,则报错;
例如:
>>> x = { 'k1':'v1','k2':'v2' }
>>> x.pop('k1')
'v1'
>>> x
{'k2': 'v2'}
>>> x.pop('k3')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'k3'
"""
pass
def popitem(self): # real signature unknown; restored from __doc__
"""
D.popitem() -> (k, v)

按照内存顺序删除字典;
例如:
>>> x = { 'k1':'v1','k2':'v2' }
>>> x.popitem()
('k2', 'v2')
>>> x.popitem()
('k1', 'v1')
>>> x.popitem()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'popitem(): dictionary is empty'
"""
pass
def setdefault(self, k, d=None): # real signature unknown; restored from __doc__
"""
D.setdefault(k[,d]) -> D.get(k,d)

设置字典key键,如果字典已存在key键,则不改变key键,并返回原有key键的value值,如果字典中不存在Key键,由为它赋值;
例如:
>>> x = { 'k1':'v1','k2':'v2' }
>>> x.setdefault('k3','v3')
'v3'
>>> x
{'k3': 'v3', 'k2': 'v2', 'k1': 'v1'}
>>> x.setdefault('k1','v3')
'v1'
>>> x
{'k3': 'v3', 'k2': 'v2', 'k1': 'v1'}
"""
pass
def update(self, E=None, **F): # known special case of dict.update
"""
D.update([E, ]**F) -> None.

更新字典;
例如:
>>> x = { 'k1':'v1','k2':'v2' }
>>> x.update({'k3':'v3'})
>>> x
{'k3': 'v3', 'k2': 'v2', 'k1': 'v1'}
"""
pass
def values(self): # real signature unknown; restored from __doc__
"""
D.values() -> list of D's values

获取字典中的值,返回列表;
例如:
>>> x = { 'k1':'v1','k2':'v2' }
>>> x.values()
['v2', 'v1']
"""
return []
def viewitems(self): # real signature unknown; restored from __doc__
"""
D.viewitems() -> a set-like object providing a view on D's items

为字典D所有对象,提供类似集合的视图; (Python2特有,Python3已删除)
例如:
>>> x = { 'k1':'v1','k2':'v2' }
>>> x.viewitems()
dict_items([('k2', 'v2'), ('k1', 'v1')])
"""
pass
def viewkeys(self): # real signature unknown; restored from __doc__
"""
D.viewkeys() -> a set-like object providing a view on D's keys

为字典D的key,提供类型集合的视图; (Python2特有,Python3已删除)
例如:
>>> x = { 'k1':'v1','k2':'v2' }
>>> x.viewkeys()
dict_keys(['k2', 'k1'])
"""
pass
def viewvalues(self): # real signature unknown; restored from __doc__
"""
D.viewvalues() -> an object providing a view on D's values

为字典D的values,提供类型集合的视图; (Python2特有,Python3已删除)
例如:
>>> x = { 'k1':'v1','k2':'v2' }
>>> y = x.viewvalues()
>>> y
dict_values(['v2', 'v1'])
"""
pass
def __cmp__(self, y): # real signature unknown; restored from __doc__
"""
x.__cmp__(y) 等同于 cmp(x,y)

用于比较两个字典元素,如果两个字典的元素相同返回0,如果字典x大于字典y返回1,如果字典x小于字典y返回-1; (Python2特有,Python3已删除)
例如:
>>> x = { 'k1':'v1','k2':'v2' }
>>> y = { 'k1':'v1','k2':'v2' }
>>> z = { 'k1':'v3','k2':'v2' }
>>> x.__cmp__(y)
0
>>> x.__cmp__(z)
-1
>>> y = { 'k1':0,'k2':'v2' }
>>> x.__cmp__(y)
1
>>> cmp(x,y)
1
"""
pass
def __contains__(self, k): # real signature unknown; restored from __doc__
"""
D.__contains__(k) -> True if D has a key k, else False

字典包含判断,即判断y是否包含在x中,返回布尔值;
"""
return False
def __delitem__(self, y): # real signature unknown; restored from __doc__
"""
x.__delitem__(y) 等同于 del x[y]

用于移除列表中指定key的元素,该方法没有返回值,如果字典为空或索引超出范围,则引报错;
例如:
>>> x = { 'k1':'v1','k2':'v2' }
>>> x.__delitem__('k1')
>>> x
{'k2': 'v2'}
>>> x.__delitem__('k3')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'k3'
"""
pass
def __eq__(self, y): # real signature unknown; restored from __doc__
"""
x.__eq__(y) 等同于 x==y

字典等同于判断,即判断x是否等于y,返回布尔值;
"""
pass
def __getattribute__(self, name): # real signature unknown; restored from __doc__
"""
x.__getattribute__('name') 等同于 x.name
"""
pass
def __getitem__(self, y): # real signature unknown; restored from __doc__
"""
x.__getitem__(y) 等同于 x[y]

返回字典指定key的value,并返回value,key值需存在于字典,否则报错;
例如:
>>> x = { 'k1':'v1','k2':'v2' }
>>> x.__getitem__('k1')
'v1'
>>> x.__getitem__('k3')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'k3'
"""
pass
def __ge__(self, y): # real signature unknown; restored from __doc__
"""
x.__ge__(y) 等同于 x>=y

字典大于等于判断,返回布尔值;
"""
pass
def __gt__(self, y): # real signature unknown; restored from __doc__
"""
x.__gt__(y) 等同于 x>y

字典大于判断,返回布尔值;
"""
pass
def __init__(self, seq=None, **kwargs): # known special case of dict.__init__
"""
dict() -> new empty dictionary
dict(mapping) -> new dictionary initialized from a mapping object's
(key, value) pairs
dict(iterable) -> new dictionary initialized as if via:
d = {}
for k, v in iterable:
d[k] = v
dict(**kwargs) -> new dictionary initialized with the name=value pairs
in the keyword argument list.  For example:  dict(one=1, two=2)
构造方法,执行x = {}时自动调用字典函数;
"""
pass
def __iter__(self): # real signature unknown; restored from __doc__
"""
x.__iter__() 等同于 iter(x)

迭代对象,返回自己;
"""
pass
def __len__(self): # real signature unknown; restored from __doc__
"""
x.__len__() 等同于 len(x)

返回字典的长度;
例如:
>>> x = { 'k1':'v1','k2':'v2' }
>>> x.__len__()
2
>>> len(x)
2
"""
pass
def __le__(self, y): # real signature unknown; restored from __doc__
"""
x.__le__(y) 等同于 x<=y

字典小于等于判断,返回布尔值;
"""
pass
def __lt__(self, y): # real signature unknown; restored from __doc__
"""
x.__lt__(y) <==> x<y

字典小于判断,返回布尔值;
"""
pass
@staticmethod # known case of __new__
def __new__(S, *more): # real signature unknown; restored from __doc__
"""
T.__new__(S, ...) -> a new object with type S, a subtype of T
"""
pass
def __ne__(self, y): # real signature unknown; restored from __doc__
"""
x.__ne__(y) 等同于 x!=y

字典不等于判断,返回布尔值;
"""
pass
def __repr__(self): # real signature unknown; restored from __doc__
"""
x.__repr__() 等同于 repr(x)

转化为解释器可读取的形式,即转换为字符串格式;
例如:
>>> x = { 'k1':'v1','k2':'v2' }
>>> x.__repr__()
"{'k2': 'v2', 'k1': 'v1'}"
>>> x
{'k2': 'v2', 'k1': 'v1'}
>>> repr(x)
"{'k2': 'v2', 'k1': 'v1'}"
"""
pass
def __setitem__(self, i, y): # real signature unknown; restored from __doc__
"""
x.__setitem__(i, y) 等同于 x[i]=y

将x字典指定key的value值替换为y,该方法直接改变x字典,但没有返回值;
例如:
>>> x = { 'k1':'v1','k2':'v2' }
>>> x.__setitem__('k1','v3')
>>> x
{'k2': 'v2', 'k1': 'v3'}
"""
pass
def __sizeof__(self): # real signature unknown; restored from __doc__
"""
D.__sizeof__() -> size of D in memory, in bytes

返回内存中的大小(以字节为单位);
"""
pass
__hash__ = None
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息