Python数据类型详解(一)字符串
一.基本数据类型
整数:int
字符串:str(注:\t等于一个tab键)
布尔值:bool
列表:list
列表用[]
元祖:tuple
元祖用()
字典:dict
注:所有的数据类型都存在想对应的类列里
二.字符串所有数据类型:
基本操作:
索引,切片,追加,删除,长度,切片,循环,包含
classstr(object): """ str(object='')->str str(bytes_or_buffer[,encoding[,errors]])->str Createanewstringobjectfromthegivenobject.Ifencodingor errorsisspecified,thentheobjectmustexposeadatabuffer thatwillbedecodedusingthegivenencodinganderrorhandler. Otherwise,returnstheresultofobject.__str__()(ifdefined) orrepr(object). encodingdefaultstosys.getdefaultencoding(). errorsdefaultsto'strict'. """ defcapitalize(self):#realsignatureunknown;restoredfrom__doc__ """ S.capitalize()->str ReturnacapitalizedversionofS,i.e.makethefirstcharacter haveuppercaseandtherestlowercase.(返回一个大写版本的年代,即第一个字符,有大写,其余小写。) """ return"" defcasefold(self):#realsignatureunknown;restoredfrom__doc__ """ S.casefold()->str ReturnaversionofSsuitableforcaselesscomparisons.(返回一个版本的S适合caseless比较。) """ return"" defcenter(self,width,fillchar=None):#realsignatureunknown;restoredfrom__doc__ """ S.center(width[,fillchar])->str ReturnScenteredinastringoflengthwidth.Paddingis doneusingthespecifiedfillcharacter(defaultisaspace)(返回年代集中在一个字符串的长度宽度。填充使用指定的填充字符(默认是一个空间)) """ return"" defcount(self,sub,start=None,end=None):#realsignatureunknown;restoredfrom__doc__ """ S.count(sub[,start[,end]])->int Returnthenumberofnon-overlappingoccurrencesofsubstringsubin stringS[start:end].Optionalargumentsstartandendare interpretedasinslicenotation. (返回的数量重叠出现的子串子字符串(开始:结束)。可选参数的开始和结束解释为片符号。) """ return0 defencode(self,encoding='utf-8',errors='strict'):#realsignatureunknown;restoredfrom__doc__ """ S.encode(encoding='utf-8',errors='strict')->bytes EncodeSusingthecodecregisteredforencoding.Defaultencoding is'utf-8'.errorsmaybegiventosetadifferenterror handlingscheme.Defaultis'strict'meaningthatencodingerrorsraise aUnicodeEncodeError.Otherpossiblevaluesare'ignore','replace'and 'xmlcharrefreplace'aswellasanyothernameregisteredwith codecs.register_errorthatcanhandleUnicodeEncodeErrors. """ returnb"" defexpandtabs(self,tabsize=8):#realsignatureunknown;restoredfrom__doc__ """ S.expandtabs(tabsize=8)->str ReturnacopyofSwherealltabcharactersareexpandedusingspaces. Iftabsizeisnotgiven,atabsizeof8charactersisassumed. (返回一个副本的年代,所有制表符使用空间扩大。如果tabsize不是,一个标签大小8个字符。) """ return"" deffind(self,sub,start=None,end=None):#realsignatureunknown;restoredfrom__doc__ """ S.find(sub[,start[,end]])->int ReturnthelowestindexinSwheresubstringsubisfound, suchthatsubiscontainedwithinS[start:end].Optional argumentsstartandendareinterpretedasinslicenotation. Return-1onfailure. (回报指数最低的年代找到子字符串的子,这样的子是包含在S[开始:结束]。可选参数中解释为开始和结束符号。) """ return0 defformat(self,*args,**kwargs):#knownspecialcaseofstr.format """ S.format(*args,**kwargs)->str ReturnaformattedversionofS,usingsubstitutionsfromargsandkwargs. Thesubstitutionsareidentifiedbybraces('{'and'}'). (返回一个格式化的年代,利用参数的替换和kwargs。替换被括号(“{”和“}”)。) """ pass defformat_map(self,mapping):#realsignatureunknown;restoredfrom__doc__ """ S.format_map(mapping)->str ReturnaformattedversionofS,usingsubstitutionsfrommapping. Thesubstitutionsareidentifiedbybraces('{'and'}'). (返回一个格式化的年代,利用映射的替换。替换被括号(“{”和“}”)。) """ return"" defindex(self,sub,start=None,end=None):#realsignatureunknown;restoredfrom__doc__ """ S.index(sub[,start[,end]])->int LikeS.find()butraiseValueErrorwhenthesubstringisnotfound. (像S.find(),但没有找到子字符串时提高ValueError) """ return0 defisalnum(self):#realsignatureunknown;restoredfrom__doc__ """ S.isalnum()->bool ReturnTrueifallcharactersinSarealphanumeric andthereisatleastonecharacterinS,Falseotherwise. (如果在年代所有的人物都是字母数字返回True和至少有一个角色年代,否则假。) """ returnFalse defisalpha(self):#realsignatureunknown;restoredfrom__doc__ """ S.isalpha()->bool ReturnTrueifallcharactersinSarealphabetic andthereisatleastonecharacterinS,Falseotherwise. (如果在年代所有的人物都是字母返回True和至少有一个角色年代,否则假。) """ returnFalse defisdigit(self):#realsignatureunknown;restoredfrom__doc__ """ S.isdigit()->bool ReturnTrueifallcharactersinSaredigits andthereisatleastonecharacterinS,Falseotherwise. (返回True,如果在年代所有的人物都是数字和至少有一个角色年代,否则假。) """ returnFalse defislower(self):#realsignatureunknown;restoredfrom__doc__ """ S.islower()->bool ReturnTrueifallcasedcharactersinSarelowercaseandthereis atleastonecasedcharacterinS,Falseotherwise. (返回True,如果所有S是小写,下套管的字符至少有一个下套管在年代,否则假。) """ returnFalse defisnumeric(self):#realsignatureunknown;restoredfrom__doc__ """ S.isnumeric()->bool ReturnTrueifthereareonlynumericcharactersinS, Falseotherwise. (返回True,如果只有数字字符,否则错误。) """ returnFalse defisprintable(self):#realsignatureunknown;restoredfrom__doc__ """ S.isprintable()->bool ReturnTrueifallcharactersinSareconsidered printableinrepr()orSisempty,Falseotherwise. (如果在年代所有的人物都是考虑返回True,可打印在repr()或年代是空的,否则假。) """ returnFalse defisspace(self):#realsignatureunknown;restoredfrom__doc__ """ S.isspace()->bool ReturnTrueifallcharactersinSarewhitespace andthereisatleastonecharacterinS,Falseotherwise. (返回True,如果在年代所有的人物都是空白和至少有一个角色年代,否则假。) """ returnFalse defistitle(self):#realsignatureunknown;restoredfrom__doc__ """ S.istitle()->bool ReturnTrueifSisatitlecasedstringandthereisatleastone characterinS,i.e.upper-andtitlecasecharactersmayonly followuncasedcharactersandlowercasecharactersonlycasedones. ReturnFalseotherwise. (返回True,如果Stitlecased字符串和至少有一个个性的年代,即上,可能只titlecase字符遵循外露的字符和小写字符只下套管。否则返回假。) """ returnFalse defisupper(self):#realsignatureunknown;restoredfrom__doc__ """ S.isupper()->bool ReturnTrueifallcasedcharactersinSareuppercaseandthereis atleastonecasedcharacterinS,Falseotherwise. (返回True,如果所有S是大写,下套管的字符至少有一个下套管在年代,否则假。) """ returnFalse defjoin(self,iterable):#realsignatureunknown;restoredfrom__doc__ """ S.join(iterable)->str Returnastringwhichistheconcatenationofthestringsinthe iterable.TheseparatorbetweenelementsisS. (返回一个字符串的连接字符串iterable。元素之间的分隔符是S。) """ return"" defljust(self,width,fillchar=None):#realsignatureunknown;restoredfrom__doc__ """ S.ljust(width[,fillchar])->str ReturnSleft-justifiedinaUnicodestringoflengthwidth.Paddingis doneusingthespecifiedfillcharacter(defaultisaspace). (返回年代左对齐的Unicode字符串的长度宽度。填充使用指定的填充字符(默认值是一个空格)。) """ return"" deflower(self):#realsignatureunknown;restoredfrom__doc__ """ S.lower()->str ReturnacopyofthestringSconvertedtolowercase. (返回的字符串转换为小写。) """ return"" deflstrip(self,chars=None):#realsignatureunknown;restoredfrom__doc__ """ S.lstrip([chars])->str ReturnacopyofthestringSwithleadingwhitespaceremoved. IfcharsisgivenandnotNone,removecharactersincharsinstead. (返回字符串的副本删除前导空白。如果字符而不是没有,删除字符字符代替。) """ return"" defpartition(self,sep):#realsignatureunknown;restoredfrom__doc__ """ S.partition(sep)->(head,sep,tail) SearchfortheseparatorsepinS,andreturnthepartbeforeit, theseparatoritself,andthepartafterit.Iftheseparatorisnot found,returnSandtwoemptystrings. (搜索分离器sep的年代,并返回之前的部分一样,分隔符本身,后一部分。如果分隔符发现,还和两个空字符串。) """ pass defreplace(self,old,new,count=None):#realsignatureunknown;restoredfrom__doc__ """ S.replace(old,new[,count])->str ReturnacopyofSwithalloccurrencesofsubstring oldreplacedbynew.Iftheoptionalargumentcountis given,onlythefirstcountoccurrencesarereplaced. (返回一个年代出现的所有子字符串的副本老被新的取代。如果可选参数计数,只替换第一计数。) """ return"" defrfind(self,sub,start=None,end=None):#realsignatureunknown;restoredfrom__doc__ """ S.rfind(sub[,start[,end]])->int ReturnthehighestindexinSwheresubstringsubisfound, suchthatsubiscontainedwithinS[start:end].Optional argumentsstartandendareinterpretedasinslicenotation. Return-1onfailure. (回报最高的指数在年代找到子字符串的子,这样的子是包含在S[开始:结束]。可选参数中解释为开始和结束符号。) """ return0 defrindex(self,sub,start=None,end=None):#realsignatureunknown;restoredfrom__doc__ """ S.rindex(sub[,start[,end]])->int LikeS.rfind()butraiseValueErrorwhenthesubstringisnotfound. (像S.rfind(),但没有找到子字符串时提高ValueError。) """ return0 defrjust(self,width,fillchar=None):#realsignatureunknown;restoredfrom__doc__ """ S.rjust(width[,fillchar])->str ReturnSright-justifiedinastringoflengthwidth.Paddingis doneusingthespecifiedfillcharacter(defaultisaspace). (返回右对齐的在一个字符串的长度宽度。填充使用指定的填充字符(默认值是一个空格)) """ return"" defrpartition(self,sep):#realsignatureunknown;restoredfrom__doc__ """ S.rpartition(sep)->(head,sep,tail) SearchfortheseparatorsepinS,startingattheendofS,andreturn thepartbeforeit,theseparatoritself,andthepartafterit.Ifthe separatorisnotfound,returntwoemptystringsandS. (寻找分离器在年代,9月开始的年代,并返回之前的部分一样,分离器本身,后一部分。如果没有找到分隔符,返回两个空字符串和年代。) """ pass defrsplit(self,sep=None,maxsplit=-1):#realsignatureunknown;restoredfrom__doc__ """ S.rsplit(sep=None,maxsplit=-1)->listofstrings ReturnalistofthewordsinS,usingsepasthe delimiterstring,startingattheendofthestringand workingtothefront.Ifmaxsplitisgiven,atmostmaxsplit splitsaredone.Ifsepisnotspecified,anywhitespacestring isaseparator. (返回一个列表的单词,使用9月作为分隔符字符串,字符串的结束和开始工作到前面来。如果maxsplit,最多maxsplit分割完成。如果没有指定9月,任何空白字符串是一个分隔符。) """ return[] defrstrip(self,chars=None):#realsignatureunknown;restoredfrom__doc__ """ S.rstrip([chars])->str ReturnacopyofthestringSwithtrailingwhitespaceremoved. IfcharsisgivenandnotNone,removecharactersincharsinstead. (返回一个字符串的副本年代尾随空格移除。如果字符而不是没有,删除字符字符代替。) """ return"" defsplit(self,sep=None,maxsplit=-1):#realsignatureunknown;restoredfrom__doc__ """ S.split(sep=None,maxsplit=-1)->listofstrings ReturnalistofthewordsinS,usingsepasthe delimiterstring.Ifmaxsplitisgiven,atmostmaxsplit splitsaredone.IfsepisnotspecifiedorisNone,any whitespacestringisaseparatorandemptystringsare removedfromtheresult. (返回一个列表的单词,使用9月作为 分隔符的字符串。如果maxsplit,最多maxsplit 分割完成。如果没有指定9月或没有, 空白字符串分隔符和空字符串 从结果中删除。) """ return[] defsplitlines(self,keepends=None):#realsignatureunknown;restoredfrom__doc__ """ S.splitlines([keepends])->listofstrings ReturnalistofthelinesinS,breakingatlineboundaries. Linebreaksarenotincludedintheresultinglistunlesskeepends isgivenandtrue.(返回一个列表的行,行打破界限。换行符不包括在结果列表,除非keepends和真正的。) """ return[] defstartswith(self,prefix,start=None,end=None):#realsignatureunknown;restoredfrom__doc__ """ S.startswith(prefix[,start[,end]])->bool ReturnTrueifSstartswiththespecifiedprefix,Falseotherwise. Withoptionalstart,testSbeginningatthatposition. Withoptionalend,stopcomparingSatthatposition. prefixcanalsobeatupleofstringstotry. (返回True,如果年代始于指定的前缀,否则假。 可选的开始,测试年代开始在那个位置。 带有可选结束,停止比较年代在那个位置。 前缀也可以尝试一个元组的字符串。) """ returnFalse defstrip(self,chars=None):#realsignatureunknown;restoredfrom__doc__ """ S.strip([chars])->str ReturnacopyofthestringSwithleadingandtrailing whitespaceremoved. IfcharsisgivenandnotNone,removecharactersincharsinstead.(返回字符串的副本与前导和尾随空格移除。如果字符而不是没有,删除字符字符代替。) """ return"" defswapcase(self):#realsignatureunknown;restoredfrom__doc__ """ S.swapcase()->str ReturnacopyofSwithuppercasecharactersconvertedtolowercase andviceversa.(返回一个副本的年代大写字符转换为小写反之亦然) """ return"" deftitle(self):#realsignatureunknown;restoredfrom__doc__ """ S.title()->str ReturnatitlecasedversionofS,i.e.wordsstartwithtitlecase characters,allremainingcasedcharactershavelowercase.(返回一个titlecased版本的年代,即单词从标题开始字符,所有剩余的下套管字符小写) """ return"" deftranslate(self,table):#realsignatureunknown;restoredfrom__doc__ """ S.translate(table)->str ReturnacopyofthestringSinwhicheachcharacterhasbeenmapped throughthegiventranslationtable.Thetablemustimplement lookup/indexingvia__getitem__,forinstanceadictionaryorlist, mappingUnicodeordinalstoUnicodeordinals,strings,orNone.If thisoperationraisesLookupError,thecharacterisleftuntouched. CharactersmappedtoNonearedeleted.(返回的字符串的每个字符被映射通过给定的转换表。 表必须实现通过__getitem__查找/索引,例如字典或列表,Unicode依次映射到Unicode序数、字符串或没有。 如果此操作提出了LookupError,字符保持不变) """ return"" defupper(self):#realsignatureunknown;restoredfrom__doc__ """ S.upper()->str ReturnacopyofSconvertedtouppercase.(返回一个副本年代转换为大写) """ return"" defzfill(self,width):#realsignatureunknown;restoredfrom__doc__ """ S.zfill(width)->str PadanumericstringSwithzerosontheleft,tofillafield ofthespecifiedwidth.ThestringSisnevertruncated.(垫一个数字字符串与0年代在左边,填补一个字段指定的宽度。字符串年代不会截断。) """ return"" def__add__(self,*args,**kwargs):#realsignatureunknown """Returnself+value.""" pass def__contains__(self,*args,**kwargs):#realsignatureunknown """Returnkeyinself.""" pass def__eq__(self,*args,**kwargs):#realsignatureunknown """Returnself==value.""" pass def__format__(self,format_spec):#realsignatureunknown;restoredfrom__doc__ """ S.__format__(format_spec)->str ReturnaformattedversionofSasdescribedbyformat_spec. """ return"" def__getattribute__(self,*args,**kwargs):#realsignatureunknown """Returngetattr(self,name).""" pass def__getitem__(self,*args,**kwargs):#realsignatureunknown """Returnself[key].""" pass def__getnewargs__(self,*args,**kwargs):#realsignatureunknown pass def__ge__(self,*args,**kwargs):#realsignatureunknown """Returnself>=value.""" pass def__gt__(self,*args,**kwargs):#realsignatureunknown """Returnself>value.""" pass def__hash__(self,*args,**kwargs):#realsignatureunknown """Returnhash(self).""" pass def__init__(self,value='',encoding=None,errors='strict'):#knownspecialcaseofstr.__init__ """ str(object='')->str str(bytes_or_buffer[,encoding[,errors]])->str Createanewstringobjectfromthegivenobject.Ifencodingor errorsisspecified,thentheobjectmustexposeadatabuffer thatwillbedecodedusingthegivenencodinganderrorhandler. Otherwise,returnstheresultofobject.__str__()(ifdefined) orrepr(object). encodingdefaultstosys.getdefaultencoding(). errorsdefaultsto'strict'. #(copiedfromclassdoc) """ pass def__iter__(self,*args,**kwargs):#realsignatureunknown """Implementiter(self).""" pass def__len__(self,*args,**kwargs):#realsignatureunknown """Returnlen(self).""" pass def__le__(self,*args,**kwargs):#realsignatureunknown """Returnself<=value.""" pass def__lt__(self,*args,**kwargs):#realsignatureunknown """Returnself<value.""" pass def__mod__(self,*args,**kwargs):#realsignatureunknown """Returnself%value.""" pass def__mul__(self,*args,**kwargs):#realsignatureunknown """Returnself*value.n""" pass @staticmethod#knowncaseof__new__ def__new__(*args,**kwargs):#realsignatureunknown """Createandreturnanewobject.Seehelp(type)foraccuratesignature.""" pass def__ne__(self,*args,**kwargs):#realsignatureunknown """Returnself!=value.""" pass def__repr__(self,*args,**kwargs):#realsignatureunknown """Returnrepr(self).""" pass def__rmod__(self,*args,**kwargs):#realsignatureunknown """Returnvalue%self.""" pass def__rmul__(self,*args,**kwargs):#realsignatureunknown """Returnself*value.""" pass def__sizeof__(self):#realsignatureunknown;restoredfrom__doc__ """S.__sizeof__()->sizeofSinmemory,inbytes""" pass def__str__(self,*args,**kwargs):#realsignatureunknown """Returnstr(self).""" pass classsuper(object): """ super()->sameassuper(__class__,<firstargument>) super(type)->unboundsuperobject super(type,obj)->boundsuperobject;requiresisinstance(obj,type) super(type,type2)->boundsuperobject;requiresissubclass(type2,type) Typicalusetocallacooperativesuperclassmethod: classC(B): defmeth(self,arg): super().meth(arg) Thisworksforclassmethodstoo: classC(B): @classmethod defcmeth(cls,arg): super().cmeth(arg) """ def__getattribute__(self,*args,**kwargs):#realsignatureunknown """Returngetattr(self,name).""" pass def__get__(self,*args,**kwargs):#realsignatureunknown """Returnanattributeofinstance,whichisoftypeowner.""" pass def__init__(self,type1=None,type2=None):#knownspecialcaseofsuper.__init__ """ super()->sameassuper(__class__,<firstargument>) super(type)->unboundsuperobject super(type,obj)->boundsuperobject;requiresisinstance(obj,type) super(type,type2)->boundsuperobject;requiresissubclass(type2,type) Typicalusetocallacooperativesuperclassmethod: classC(B): defmeth(self,arg): super().meth(arg) Thisworksforclassmethodstoo: classC(B): @classmethod defcmeth(cls,arg): super().cmeth(arg) #(copiedfromclassdoc) """ pass @staticmethod#knowncaseof__new__ def__new__(*args,**kwargs):#realsignatureunknown """Createandreturnanewobject.Seehelp(type)foraccuratesignature.""" pass def__repr__(self,*args,**kwargs):#realsignatureunknown """Returnrepr(self).""" pass __self_class__=property(lambdaself:type(object)) """thetypeoftheinstanceinvokingsuper();maybeNone :type:type """ __self__=property(lambdaself:type(object)) """theinstanceinvokingsuper();maybeNone :type:type """ __thisclass__=property(lambdaself:type(object)) """theclassinvokingsuper() :type:type """ classSyntaxWarning(Warning): """Baseclassforwarningsaboutdubioussyntax.""" def__init__(self,*args,**kwargs):#realsignatureunknown pass @staticmethod#knowncaseof__new__ def__new__(*args,**kwargs):#realsignatureunknown """Createandreturnanewobject.Seehelp(type)foraccuratesignature.""" pass classSystemError(Exception): """ InternalerrorinthePythoninterpreter. PleasereportthistothePythonmaintainer,alongwiththetraceback, thePythonversion,andthehardware/OSplatformandversion. """ def__init__(self,*args,**kwargs):#realsignatureunknown pass @staticmethod#knowncaseof__new__ def__new__(*args,**kwargs):#realsignatureunknown """Createandreturnanewobject.Seehelp(type)foraccuratesignature.""" pass classSystemExit(BaseException): """Requesttoexitfromtheinterpreter.""" def__init__(self,*args,**kwargs):#realsignatureunknown pass code=property(lambdaself:object(),lambdaself,v:None,lambdaself:None)#default """exceptioncode""" classTabError(IndentationError): """Impropermixtureofspacesandtabs.""" def__init__(self,*args,**kwargs):#realsignatureunknown pass classTimeoutError(OSError): """Timeoutexpired.""" def__init__(self,*args,**kwargs):#realsignatureunknown pass classtuple(object): """ tuple()->emptytuple tuple(iterable)->tupleinitializedfromiterable'sitems Iftheargumentisatuple,thereturnvalueisthesameobject. """ defcount(self,value):#realsignatureunknown;restoredfrom__doc__ """T.count(value)->integer--returnnumberofoccurrencesofvalue""" return0 defindex(self,value,start=None,stop=None):#realsignatureunknown;restoredfrom__doc__ """ T.index(value,[start,[stop]])->integer--returnfirstindexofvalue. RaisesValueErrorifthevalueisnotpresent. """ return0 def__add__(self,*args,**kwargs):#realsignatureunknown """Returnself+value.""" pass def__contains__(self,*args,**kwargs):#realsignatureunknown """Returnkeyinself.""" pass def__eq__(self,*args,**kwargs):#realsignatureunknown """Returnself==value.""" pass def__getattribute__(self,*args,**kwargs):#realsignatureunknown """Returngetattr(self,name).""" pass def__getitem__(self,*args,**kwargs):#realsignatureunknown """Returnself[key].""" pass def__getnewargs__(self,*args,**kwargs):#realsignatureunknown pass def__ge__(self,*args,**kwargs):#realsignatureunknown """Returnself>=value.""" pass def__gt__(self,*args,**kwargs):#realsignatureunknown """Returnself>value.""" pass def__hash__(self,*args,**kwargs):#realsignatureunknown """Returnhash(self).""" pass def__init__(self,seq=()):#knownspecialcaseoftuple.__init__ """ tuple()->emptytuple tuple(iterable)->tupleinitializedfromiterable'sitems Iftheargumentisatuple,thereturnvalueisthesameobject. #(copiedfromclassdoc) """ pass def__iter__(self,*args,**kwargs):#realsignatureunknown """Implementiter(self).""" pass def__len__(self,*args,**kwargs):#realsignatureunknown """Returnlen(self).""" pass def__le__(self,*args,**kwargs):#realsignatureunknown """Returnself<=value.""" pass def__lt__(self,*args,**kwargs):#realsignatureunknown """Returnself<value.""" pass def__mul__(self,*args,**kwargs):#realsignatureunknown """Returnself*value.n""" pass @staticmethod#knowncaseof__new__ def__new__(*args,**kwargs):#realsignatureunknown """Createandreturnanewobject.Seehelp(type)foraccuratesignature.""" pass def__ne__(self,*args,**kwargs):#realsignatureunknown """Returnself!=value.""" pass def__repr__(self,*args,**kwargs):#realsignatureunknown """Returnrepr(self).""" pass def__rmul__(self,*args,**kwargs):#realsignatureunknown """Returnself*value.""" pass classtype(object): """ type(object_or_name,bases,dict) type(object)->theobject'stype type(name,bases,dict)->anewtype """ defmro(self):#realsignatureunknown;restoredfrom__doc__ """ mro()->list returnatype'smethodresolutionorder """ return[] def__call__(self,*args,**kwargs):#realsignatureunknown """Callselfasafunction.""" pass def__delattr__(self,*args,**kwargs):#realsignatureunknown """Implementdelattr(self,name).""" pass def__dir__(self):#realsignatureunknown;restoredfrom__doc__ """ __dir__()->list specialized__dir__implementationfortypes """ return[] def__getattribute__(self,*args,**kwargs):#realsignatureunknown """Returngetattr(self,name).""" pass def__init__(cls,what,bases=None,dict=None):#knownspecialcaseoftype.__init__ """ type(object_or_name,bases,dict) type(object)->theobject'stype type(name,bases,dict)->anewtype #(copiedfromclassdoc) """ pass def__instancecheck__(self):#realsignatureunknown;restoredfrom__doc__ """ __instancecheck__()->bool checkifanobjectisaninstance """ returnFalse @staticmethod#knowncaseof__new__ def__new__(*args,**kwargs):#realsignatureunknown """Createandreturnanewobject.Seehelp(type)foraccuratesignature.""" pass def__prepare__(self):#realsignatureunknown;restoredfrom__doc__ """ __prepare__()->dict usedtocreatethenamespacefortheclassstatement """ return{} def__repr__(self,*args,**kwargs):#realsignatureunknown """Returnrepr(self).""" pass def__setattr__(self,*args,**kwargs):#realsignatureunknown """Implementsetattr(self,name,value).""" pass def__sizeof__(self):#realsignatureunknown;restoredfrom__doc__ """ __sizeof__()->int returnmemoryconsumptionofthetypeobject """ return0 def__subclasscheck__(self):#realsignatureunknown;restoredfrom__doc__ """ __subclasscheck__()->bool checkifaclassisasubclass """ returnFalse def__subclasses__(self):#realsignatureunknown;restoredfrom__doc__ """__subclasses__()->listofimmediatesubclasses""" return[] __abstractmethods__=property(lambdaself:object(),lambdaself,v:None,lambdaself:None)#default __bases__=( object, ) __base__=object __basicsize__=864 __dictoffset__=264 __dict__=None#(!)realvalueis'' __flags__=-2146675712 __itemsize__=40 __mro__=( None,#(!)forward:type,realvalueis'' object, ) __name__='type' __qualname__='type' __text_signature__=None __weakrefoffset__=368 classTypeError(Exception): """Inappropriateargumenttype.""" def__init__(self,*args,**kwargs):#realsignatureunknown pass @staticmethod#knowncaseof__new__ def__new__(*args,**kwargs):#realsignatureunknown """Createandreturnanewobject.Seehelp(type)foraccuratesignature.""" pass classUnboundLocalError(NameError): """Localnamereferencedbutnotboundtoavalue.""" def__init__(self,*args,**kwargs):#realsignatureunknown pass @staticmethod#knowncaseof__new__ def__new__(*args,**kwargs):#realsignatureunknown """Createandreturnanewobject.Seehelp(type)foraccuratesignature.""" pass classValueError(Exception): """Inappropriateargumentvalue(ofcorrecttype).""" def__init__(self,*args,**kwargs):#realsignatureunknown pass @staticmethod#knowncaseof__new__ def__new__(*args,**kwargs):#realsignatureunknown """Createandreturnanewobject.Seehelp(type)foraccuratesignature.""" pass classUnicodeError(ValueError): """Unicoderelatederror.""" def__init__(self,*args,**kwargs):#realsignatureunknown pass @staticmethod#knowncaseof__new__ def__new__(*args,**kwargs):#realsignatureunknown """Createandreturnanewobject.Seehelp(type)foraccuratesignature.""" pass classUnicodeDecodeError(UnicodeError): """Unicodedecodingerror.""" def__init__(self,*args,**kwargs):#realsignatureunknown pass @staticmethod#knowncaseof__new__ def__new__(*args,**kwargs):#realsignatureunknown """Createandreturnanewobject.Seehelp(type)foraccuratesignature.""" pass def__str__(self,*args,**kwargs):#realsignatureunknown """Returnstr(self).""" pass encoding=property(lambdaself:object(),lambdaself,v:None,lambdaself:None)#default """exceptionencoding""" end=property(lambdaself:object(),lambdaself,v:None,lambdaself:None)#default """exceptionend""" object=property(lambdaself:object(),lambdaself,v:None,lambdaself:None)#default """exceptionobject""" reason=property(lambdaself:object(),lambdaself,v:None,lambdaself:None)#default """exceptionreason""" start=property(lambdaself:object(),lambdaself,v:None,lambdaself:None)#default """exceptionstart""" classUnicodeEncodeError(UnicodeError): """Unicodeencodingerror.""" def__init__(self,*args,**kwargs):#realsignatureunknown pass @staticmethod#knowncaseof__new__ def__new__(*args,**kwargs):#realsignatureunknown """Createandreturnanewobject.Seehelp(type)foraccuratesignature.""" pass def__str__(self,*args,**kwargs):#realsignatureunknown """Returnstr(self).""" pass encoding=property(lambdaself:object(),lambdaself,v:None,lambdaself:None)#default """exceptionencoding""" end=property(lambdaself:object(),lambdaself,v:None,lambdaself:None)#default """exceptionend""" object=property(lambdaself:object(),lambdaself,v:None,lambdaself:None)#default """exceptionobject""" reason=property(lambdaself:object(),lambdaself,v:None,lambdaself:None)#default """exceptionreason""" start=property(lambdaself:object(),lambdaself,v:None,lambdaself:None)#default """exceptionstart""" classUnicodeTranslateError(UnicodeError): """Unicodetranslationerror.""" def__init__(self,*args,**kwargs):#realsignatureunknown pass @staticmethod#knowncaseof__new__ def__new__(*args,**kwargs):#realsignatureunknown """Createandreturnanewobject.Seehelp(type)foraccuratesignature.""" pass def__str__(self,*args,**kwargs):#realsignatureunknown """Returnstr(self).""" pass encoding=property(lambdaself:object(),lambdaself,v:None,lambdaself:None)#default """exceptionencoding""" end=property(lambdaself:object(),lambdaself,v:None,lambdaself:None)#default """exceptionend""" object=property(lambdaself:object(),lambdaself,v:None,lambdaself:None)#default """exceptionobject""" reason=property(lambdaself:object(),lambdaself,v:None,lambdaself:None)#default """exceptionreason""" start=property(lambdaself:object(),lambdaself,v:None,lambdaself:None)#default """exceptionstart""" classUnicodeWarning(Warning): """ BaseclassforwarningsaboutUnicoderelatedproblems,mostly relatedtoconversionproblems. """ def__init__(self,*args,**kwargs):#realsignatureunknown pass @staticmethod#knowncaseof__new__ def__new__(*args,**kwargs):#realsignatureunknown """Createandreturnanewobject.Seehelp(type)foraccuratesignature.""" pass classUserWarning(Warning): """Baseclassforwarningsgeneratedbyusercode.""" def__init__(self,*args,**kwargs):#realsignatureunknown pass @staticmethod#knowncaseof__new__ def__new__(*args,**kwargs):#realsignatureunknown """Createandreturnanewobject.Seehelp(type)foraccuratesignature.""" pass classZeroDivisionError(ArithmeticError): """Secondargumenttoadivisionormodulooperationwaszero.""" def__init__(self,*args,**kwargs):#realsignatureunknown pass @staticmethod#knowncaseof__new__ def__new__(*args,**kwargs):#realsignatureunknown """Createandreturnanewobject.Seehelp(type)foraccuratesignature.""" pass classzip(object): """ zip(iter1[,iter2[...]])-->zipobject Returnazipobjectwhose.__next__()methodreturnsatuplewhere thei-thelementcomesfromthei-thiterableargument.The.__next__() methodcontinuesuntiltheshortestiterableintheargumentsequence isexhaustedandthenitraisesStopIteration. """ def__getattribute__(self,*args,**kwargs):#realsignatureunknown """Returngetattr(self,name).""" pass def__init__(self,iter1,iter2=None,*some):#realsignatureunknown;restoredfrom__doc__ pass def__iter__(self,*args,**kwargs):#realsignatureunknown """Implementiter(self).""" pass @staticmethod#knowncaseof__new__ def__new__(*args,**kwargs):#realsignatureunknown """Createandreturnanewobject.Seehelp(type)foraccuratesignature.""" pass def__next__(self,*args,**kwargs):#realsignatureunknown """Implementnext(self).""" pass def__reduce__(self,*args,**kwargs):#realsignatureunknown """Returnstateinformationforpickling.""" pass class__loader__(object): """ Metapathimportforbuilt-inmodules. Allmethodsareeitherclassorstaticmethodstoavoidtheneedto instantiatetheclass. """ defcreate_module(self,*args,**kwargs):#realsignatureunknown """Createabuilt-inmodule""" pass defexec_module(self,*args,**kwargs):#realsignatureunknown """Execabuilt-inmodule""" pass deffind_module(self,*args,**kwargs):#realsignatureunknown """ Findthebuilt-inmodule. If'path'iseverspecifiedthenthesearchisconsideredafailure. Thismethodisdeprecated.Usefind_spec()instead. """ pass deffind_spec(self,*args,**kwargs):#realsignatureunknown pass defget_code(self,*args,**kwargs):#realsignatureunknown """ReturnNoneasbuilt-inmodulesdonothavecodeobjects.""" pass defget_source(self,*args,**kwargs):#realsignatureunknown """ReturnNoneasbuilt-inmodulesdonothavesourcecode.""" pass defis_package(self,*args,**kwargs):#realsignatureunknown """ReturnFalseasbuilt-inmodulesareneverpackages.""" pass defload_module(self,*args,**kwargs):#realsignatureunknown """ Loadthespecifiedmoduleintosys.modulesandreturnit. Thismethodisdeprecated.Useloader.exec_moduleinstead. """ pass defmodule_repr(module):#reliablyrestoredbyinspect """ Returnreprforthemodule. Themethodisdeprecated.Theimportmachinerydoesthejobitself. """ pass def__init__(self,*args,**kwargs):#realsignatureunknown pass __weakref__=property(lambdaself:object(),lambdaself,v:None,lambdaself:None)#default """listofweakreferencestotheobject(ifdefined)""" __dict__=None#(!)realvalueis'' #variableswithcomplexvalues Ellipsis=None#(!)realvalueis'' NotImplemented=None#(!)realvalueis'' __spec__=None#(!)realvalueis''
三.所有字符串数据类型举例
#变量名字变大写 tmp="zhangyanlin" tmp_new=tmp.upper() print(tmp_new) #输出所有字符定义的所有类型 tmp.upper() print(dir(tmp)) #['__add__','__class__','__contains__','__delattr__','__dir__','__doc__','__eq__','__format__','__ge__','__getattribute__','__getitem__','__getnewargs__','__gt__','__hash__','__init__','__iter__','__le__','__len__','__lt__','__mod__','__mul__','__ne__','__new__','__reduce__','__reduce_ex__','__repr__','__rmod__','__rmul__','__setattr__','__sizeof__','__str__','__subclasshook__','capitalize','casefold','center','count','encode','endswith','expandtabs','find','format','format_map','index','isalnum','isalpha','isdecimal','isdigit','isidentifier','islower','isnumeric','isprintable','isspace','istitle','isupper','join','ljust','lower','lstrip','maketrans','partition','replace','rfind','rindex','rjust','rpartition','rsplit','rstrip','split','splitlines','startswith','strip','swapcase','title','translate','upper','zfill'] #把首字母变成大写 u1="zhang" u2=u1.capitalize() print(u2) #20定义20个位,不够用_补全。 u1="zhang" u2=u1.center(20,'_') print(u2) #看zh在前10位出现了几次 u1="zhangyanliniszhgod" u2=u1.count('zh',0,10) print(u2) #获取字符串中大于等于0的位置,小于2的位置 u1="zhang" print(u1.endswith('h',0,2)) #将tab转换成空格 u1="zhang\t123" print(u1.expandtabs(20)) #找位数,相同只能找第一个出现的,没有想应得会反馈-1 u1="zhanghello" print(u1.find('h')) #站位符0和1是代表站位符 u1="name{0},age{1}" print(u1.format("zhang",18)) u1="zhangisyan" #判断是否是字母 print(u1.isalpha()) #判断是否是数字 print(u1.isdigit()) #判断是否是字母和数字 print(u1.isalnum()) #判断是否是小写 print(u1.islower()) #判断是否是空格 print(u1.isspace()) #判断是不是标题 print(u1.istitle()) #判断是不是全部都是大写 print(u1.isupper()) #把列表里的内容连接一起 print("_".join(u1)) #内容左对齐,右侧填充 print(u1.ljust(1)) #内容变小写 print(u1.lower()) #移除左边的空格 print(u1.lstrip()) #移除右边的空格 print(u1.rstrip()) #把有空格的内容分割,变成元祖类型,从左找;rpartition从右开始分割 print(u1.partition('is')) #替换,后面可以加替换几个,从左往右 print(u1.replace('zh','ZH')) #找到一个字符分割,从右,split从左分割 print(u1.rsplit('a',1)) #是否以某个字符串开始开始 print(u1.startswith('z')) #移除两边空格(strip) print(u1.strip()) #大写变小写,小写变大写 print(u1.swapcase()) #变大写(upper) print(u1.upper())
四.索引
u1="zhangyanlin" print(u1[0]) print(u1[1]) print(u1[2]) print(u1[3]) print(u1[4]) print(u1[5])
五.切片
#切出zhan,注:0是代表第一位,4代表小于四,知道第三个数 u1="zhangyanlin" print(u1[0:4])
六.循环切片
1.while使用
u1="zhangyanlin" u2=0 whileu2<len(u1): print(u1[u2]) u2+=1
2.for使用
#循环切片 u1="zhangyanlin" foru2inu1: print(u2) #循环切片,输出除了y u1="zhangyanlin" foru2inu1: ifu2=="y": continue print(u2) #循环切片,输出到y后不执行 u1="zhangyanlin" foru2inu1: ifu2=="y": break print(u2)