标签:python基本数据类型
一、str的函数说明
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的函数说明
class list(object): """ list() -> new empty list list(iterable) -> new list initialized from iterable‘s items """ def append(self, p_object): # real signature unknown; restored from __doc__ """ L.append(object) -- append object to end """ pass def count(self, value): # real signature unknown; restored from __doc__ """ L.count(value) -> integer -- return number of occurrences of value """ return 0 def extend(self, iterable): # real signature unknown; restored from __doc__ """ L.extend(iterable) -- extend list by appending elements from the iterable """ pass def index(self, value, start=None, stop=None): # real signature unknown; restored from __doc__ """ L.index(value, [start, [stop]]) -> integer -- return first index of value. Raises ValueError if the value is not present. """ return 0 def insert(self, index, p_object): # real signature unknown; restored from __doc__ """ L.insert(index, object) -- insert object before index """ pass def pop(self, index=None): # real signature unknown; restored from __doc__ """ L.pop([index]) -> item -- remove and return item at index (default last). Raises IndexError if list is empty or index is out of range. """ pass def remove(self, value): # real signature unknown; restored from __doc__ """ L.remove(value) -- remove first occurrence of value. Raises ValueError if the value is not present. """ pass def reverse(self): # real signature unknown; restored from __doc__ """ L.reverse() -- reverse *IN PLACE* """ pass def sort(self, cmp=None, key=None, reverse=False): # real signature unknown; restored from __doc__ """ L.sort(cmp=None, key=None, reverse=False) -- stable sort *IN PLACE*; cmp(x, y) -> -1, 0, 1 """ pass 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 __delitem__(self, y): # real signature unknown; restored from __doc__ """ x.__delitem__(y) <==> del x[y] """ pass def __delslice__(self, i, j): # real signature unknown; restored from __doc__ """ x.__delslice__(i, j) <==> del x[i:j] Use of negative indices is not supported. """ 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 __getslice__(self, i, j): # real signature unknown; restored from __doc__ """ x.__getslice__(i, j) <==> x[i:j] Use of negative indices is not supported. """ 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 __iadd__(self, y): # real signature unknown; restored from __doc__ """ x.__iadd__(y) <==> x+=y """ pass def __imul__(self, y): # real signature unknown; restored from __doc__ """ x.__imul__(y) <==> x*=y """ pass def __init__(self, seq=()): # known special case of list.__init__ """ list() -> new empty list list(iterable) -> new list initialized from iterable‘s items # (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 __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 """ pass def __setitem__(self, i, y): # real signature unknown; restored from __doc__ """ x.__setitem__(i, y) <==> x[i]=y """ pass def __setslice__(self, i, j, y): # real signature unknown; restored from __doc__ """ x.__setslice__(i, j, y) <==> x[i:j]=y Use of negative indices is not supported. """ pass def __sizeof__(self): # real signature unknown; restored from __doc__ """ L.__sizeof__() -- size of L in memory, in bytes """ pass __hash__ = None
本文出自 “m199369309” 博客,请务必保留此出处http://434727.blog.51cto.com/424727/1894497
标签:python基本数据类型
原文地址:http://434727.blog.51cto.com/424727/1894497