为了正常的体验网站,请在浏览器设置里面开启Javascript功能!
首页 > python函数中文手册

python函数中文手册

2022-07-04 6页 doc 470KB 12阅读

用户头像 个人认证

is_778177

暂无简介

举报
python函数中文手册Fourshortwordssumupwhathasliftedmostsuccessfulindividualsabovethecrowd:alittlebitmore.------------------------------------------author------------------------------------------datepython函数中文手册python函数中文手册python函数中文手册--------------------------------------------------...
python函数中文手册
Fourshortwordssumupwhathasliftedmostsuccessfulindividualsabovethecrowd:alittlebitmore.------------------------------------------author------------------------------------------datepython函数中文手册python函数中文手册python函数中文手册----------------------------------------------------------------------------------------------------python函数中文手册--------------------------------------------------内置函数文档说明原始文档来自于pythonv2.7.2中文译文和用法尚不完全,您可以自由修改和完善,您可以在文档结尾鸣谢添上您的名字,我们将会感谢您做的贡献!二,函数列1,取绝对值abs(x)Returntheabsolutevalueofanumber.Theargumentmaybeaplainorlongintegerorafloatingpointnumber.Iftheargumentisacomplexnumber,itsmagnitudeisreturned.如果你不知道绝对值什么意思,那就要补一下小学数学了!基本用法2,all(iterable)ReturnTrueifallelementsoftheiterablearetrue(oriftheiterableisempty).Equivalentto:3.any(iterable)ReturnTrueifanyelementoftheiterableistrue.Iftheiterableisempty,returnFalse.Equivalentto:4.basestring()ThisabstracttypeisthesuperclassforHYPERLINK"mk:@MSITStore:D:\\Python_v2.4zh\\jb51.net\\python272.chm::/library/functions.html"\l"str#str"\o"str"strandHYPERLINK"mk:@MSITStore:D:\\Python_v2.4zh\\jb51.net\\python272.chm::/library/functions.html"\l"unicode#unicode"\o"unicode"unicode.Itcannotbecalledorinstantiated,butitcanbeusedtotestwhetheranobjectisaninstanceofHYPERLINK"mk:@MSITStore:D:\\Python_v2.4zh\\jb51.net\\python272.chm::/library/functions.html"\l"str#str"\o"str"strorHYPERLINK"mk:@MSITStore:D:\\Python_v2.4zh\\jb51.net\\python272.chm::/library/functions.html"\l"unicode#unicode"\o"unicode"unicode.isinstance(obj,basestring)isequivalenttoisinstance(obj,(str,unicode)).是字符串和字符编码的超类,是抽象类型。不能被调用或者实例化。可以用来判断实例是否为字符串或者字符编码。方法:5.二进制转换bin(x)Convertanintegernumbertoabinarystring.TheresultisavalidPythonexpression.IfxisnotaPythonHYPERLINK"mk:@MSITStore:D:\\Python_v2.4zh\\jb51.net\\python272.chm::/library/functions.html"\l"int#int"\o"int"intobject,ithastodefineanHYPERLINK"mk:@MSITStore:D:\\Python_v2.4zh\\jb51.net\\python272.chm::/reference/datamodel.html"\l"object.__index__"\o"object.__index__"__index__()methodthatreturnsaninteger.转换成二进制表达方法:6.布尔类型bool([x])ConvertavaluetoaBoolean,usingthestandardtruthtestingprocedure.Ifxisfalseoromitted,thisreturnsHYPERLINK"mk:@MSITStore:D:\\Python_v2.4zh\\jb51.net\\python272.chm::/library/constants.html"\l"False"\o"False"False;otherwiseitreturnsHYPERLINK"mk:@MSITStore:D:\\Python_v2.4zh\\jb51.net\\python272.chm::/library/constants.html"\l"True"\o"True"True.HYPERLINK"mk:@MSITStore:D:\\Python_v2.4zh\\jb51.net\\python272.chm::/library/functions.html"\l"bool#bool"\o"bool"boolisalsoaclass,whichisasubclassofHYPERLINK"mk:@MSITStore:D:\\Python_v2.4zh\\jb51.net\\python272.chm::/library/functions.html"\l"int#int"\o"int"int.ClassHYPERLINK"mk:@MSITStore:D:\\Python_v2.4zh\\jb51.net\\python272.chm::/library/functions.html"\l"bool#bool"\o"bool"boolcannotbesubclassedfurther.ItsonlyinstancesareHYPERLINK"mk:@MSITStore:D:\\Python_v2.4zh\\jb51.net\\python272.chm::/library/constants.html"\l"False"\o"False"FalseandHYPERLINK"mk:@MSITStore:D:\\Python_v2.4zh\\jb51.net\\python272.chm::/library/constants.html"\l"True"\o"True"True布尔类型的转化用法:7.二进制数组的转化bytearray([source[,encoding[,errors]]])Returnanewarrayofbytes.TheHYPERLINK"mk:@MSITStore:D:\\Python_v2.4zh\\jb51.net\\python272.chm::/library/functions.html"\l"bytearray#bytearray"\o"bytearray"bytearraytypeisamutablesequenceofintegersintherange0<=x<256.Ithasmostoftheusualmethodsofmutablesequences,describedinHYPERLINK"mk:@MSITStore:D:\\Python_v2.4zh\\jb51.net\\python272.chm::/library/stdtypes.html"\l"typesseq-mutable"MutableSequenceTypes,aswellasmostmethodsthattheHYPERLINK"mk:@MSITStore:D:\\Python_v2.4zh\\jb51.net\\python272.chm::/library/functions.html"\l"str#str"\o"str"strtypehas,seeHYPERLINK"mk:@MSITStore:D:\\Python_v2.4zh\\jb51.net\\python272.chm::/library/stdtypes.html"\l"string-methods"StringMethods.Theoptionalsourceparametercanbeusedtoinitializethearrayinafewdifferentways:Ifitisastring,youmustalsogivetheencoding(andoptionally,errors)parameters;HYPERLINK"mk:@MSITStore:D:\\Python_v2.4zh\\jb51.net\\python272.chm::/library/functions.html"\l"bytearray#bytearray"\o"bytearray"bytearray()thenconvertsthestringtobytesusingHYPERLINK"mk:@MSITStore:D:\\Python_v2.4zh\\jb51.net\\python272.chm::/library/stdtypes.html"\l"str.encode"\o"str.encode"str.encode().Ifitisaninteger,thearraywillhavethatsizeandwillbeinitializedwithnullbytes.Ifitisanobjectconformingtothebufferinterface,aread-onlybufferoftheobjectwillbeusedtoinitializethebytesarray.Ifitisaniterable,itmustbeaniterableofintegersintherange0<=x<256,whichareusedastheinitialcontentsofthearray.Withoutanargument,anarrayofsize0iscreated.8.callable(object)ReturnHYPERLINK"mk:@MSITStore:D:\\Python_v2.4zh\\jb51.net\\python272.chm::/library/constants.html"\l"True"\o"True"Trueiftheobjectargumentappearscallable,HYPERLINK"mk:@MSITStore:D:\\Python_v2.4zh\\jb51.net\\python272.chm::/library/constants.html"\l"False"\o"False"Falseifnot.Ifthisreturnstrue,itisstillpossiblethatacallfails,butifitisfalse,callingobjectwillneversucceed.Notethatclassesarecallable(callingaclassreturnsanewinstance);classinstancesarecallableiftheyhaveaHYPERLINK"mk:@MSITStore:D:\\Python_v2.4zh\\jb51.net\\python272.chm::/reference/datamodel.html"\l"object.__call__"\o"object.__call__"__call__()method.9.数字转化成字符chr(i)ReturnastringofonecharacterwhoseASCIIcodeistheintegeri.Forexample,chr(97)returnsthestring'a'.ThisistheinverseofHYPERLINK"mk:@MSITStore:D:\\Python_v2.4zh\\jb51.net\\python272.chm::/library/functions.html"\l"ord#ord"\o"ord"ord().Theargumentmustbeintherange[0..255],inclusive;HYPERLINK"mk:@MSITStore:D:\\Python_v2.4zh\\jb51.net\\python272.chm::/library/exceptions.html"\l"exceptions.ValueError"\o"exceptions.ValueError"ValueErrorwillberaisedifiisoutsidethatrange.SeealsoHYPERLINK"mk:@MSITStore:D:\\Python_v2.4zh\\jb51.net\\python272.chm::/library/functions.html"\l"unichr#unichr"\o"unichr"unichr().用法:10.classmethod(function)Returnaclassmethodforfunction.Aclassmethodreceivestheclassasimplicitfirstargument,justlikeaninstancemethodreceivestheinstance.Todeclareaclassmethod,usethisidiom:11.两两比较cmp(x,y)Comparethetwoobjectsxandyandreturnanintegeraccordingtotheoutcome.Thereturnvalueisnegativeifxy.X小于X输出负(-1),X等于Y输出零(0),X大于Y输出正(1)用法:12.compile(source,filename,mode[,flags[,dont_inherit]])CompilethesourceintoacodeorASTobject.CodeobjectscanbeexecutedbyanHYPERLINK"mk:@MSITStore:D:\\Python_v2.4zh\\jb51.net\\python272.chm::/reference/simple_stmts.html"\l"exec"execstatementorevaluatedbyacalltoHYPERLINK"mk:@MSITStore:D:\\Python_v2.4zh\\jb51.net\\python272.chm::/library/functions.html"\l"eval#eval"\o"eval"eval().sourcecaneitherbeastringoranASTobject.RefertotheHYPERLINK"mk:@MSITStore:D:\\Python_v2.4zh\\jb51.net\\python272.chm::/library/ast.html"\l"module-ast"\o"AbstractSyntaxTreeclassesandmanipulation."astmoduledocumentationforinformationonhowtoworkwithASTobjects.13.complex([real[,imag]])Createacomplexnumberwiththevaluereal+imag*jorconvertastringornumbertoacomplexnumber.Ifthefirstparameterisastring,itwillbeinterpretedasacomplexnumberandthefunctionmustbecalledwithoutasecondparameter.Thesecondparametercanneverbeastring.Eachargumentmaybeanynumerictype(includingcomplex).Ifimagisomitted,itdefaultstozeroandthefunctionservesasanumericconversionfunctionlikeHYPERLINK"mk:@MSITStore:D:\\Python_v2.4zh\\jb51.net\\python272.chm::/library/functions.html"\l"int#int"\o"int"int(),HYPERLINK"mk:@MSITStore:D:\\Python_v2.4zh\\jb51.net\\python272.chm::/library/functions.html"\l"long#long"\o"long"long()andHYPERLINK"mk:@MSITStore:D:\\Python_v2.4zh\\jb51.net\\python272.chm::/library/functions.html"\l"float#float"\o"float"float().Ifbothargumentsareomitted,returns0j.14.delattr(object,name)ThisisarelativeofHYPERLINK"mk:@MSITStore:D:\\Python_v2.4zh\\jb51.net\\python272.chm::/library/functions.html"\l"setattr#setattr"\o"setattr"setattr().Theargumentsareanobjectandastring.Thestringmustbethenameofoneoftheobject’sattributes.Thefunctiondeletesthenamedattribute,providedtheobjectallowsit.Forexample,delattr(x,'foobar')isequivalenttodelx.foobar.15.字典dict([arg])Createanewdatadictionary,optionallywithitemstakenfromarg.ThedictionarytypeisdescribedinHYPERLINK"mk:@MSITStore:D:\\Python_v2.4zh\\jb51.net\\python272.chm::/library/stdtypes.html"\l"typesmapping"MappingTypes—dict.ForothercontainersseethebuiltinHYPERLINK"mk:@MSITStore:D:\\Python_v2.4zh\\jb51.net\\python272.chm::/library/functions.html"\l"list#list"\o"list"list,HYPERLINK"mk:@MSITStore:D:\\Python_v2.4zh\\jb51.net\\python272.chm::/library/stdtypes.html"\l"set"\o"set"set,andHYPERLINK"mk:@MSITStore:D:\\Python_v2.4zh\\jb51.net\\python272.chm::/library/functions.html"\l"tuple#tuple"\o"tuple"tupleclasses,andtheHYPERLINK"mk:@MSITStore:D:\\Python_v2.4zh\\jb51.net\\python272.chm::/library/collections.html"\l"module-collections"\o"High-performancedatatypes"collectionsmodule.16.很重要的函数,属性输出dir([object])Withoutarguments,returnthelistofnamesinthecurrentlocalscope.Withanargument,attempttoreturnalistofvalidattributesforthatobject.方法17.divmod(a,b)Taketwo(noncomplex)numbersasargumentsandreturnapairofnumbersconsistingoftheirquotientandremainderwhenusinglongdivision.Withmixedoperandtypes,therulesforbinaryarithmeticoperatorsapply.Forplainandlongintegers,theresultisthesameas(a//b,a%b).Forfloatingpointnumberstheresultis(q,a%b),whereqisusuallymath.floor(a/b)butmaybe1lessthanthat.Inanycaseq*b+a%bisveryclosetoa,ifa%bisnon-zeroithasthesamesignasb,and0<=abs(a%b)
/
本文档为【python函数中文手册】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索