资源描述:
《python函数中文手册》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、内置函数一,文档说明原始文档来自于pythonv2.7.2中文译文和用法尚不完全,您可以自由修改和完善,您可以在文档结尾鸣谢添上您的名字,我们将会感谢您做的贡献!二,函数列表1,取绝对值abs(x)Returntheabsolutevalueofanumber.Theargumentmaybeaplainorlongintegerorafloatingpointnumber.Iftheargumentisacomplexnumber,itsmagnitudeisreturned.如果你不知道绝对值什么意思,那就要补一下小学数学了!基本用法2,a
2、ll(iterable)ReturnTrueifallelementsoftheiterablearetrue(oriftheiterableisempty).Equivalentto:3.any(iterable)ReturnTrueifanyelementoftheiterableistrue.Iftheiterableisempty,returnFalse.Equivalentto:4.basestring()Thisabstracttypeisthesuperclassforstrandunicode.Itcannotbecalledo
3、rinstantiated,butitcanbeusedtotestwhetheranobjectisaninstanceofstrorunicode.isinstance(obj,basestring)isequivalenttoisinstance(obj,(str,unicode)).是字符串和字符编码的超类,是抽象类型。不能被调用或者实例化。可以用来判断实例是否为字符串或者字符编码。方法:5.二进制转换bin(x)Convertanintegernumbertoabinarystring.TheresultisavalidPythone
4、xpression.IfxisnotaPythonintobject,ithastodefinean__index__()methodthatreturnsaninteger.转换成二进制表达方法:6.布尔类型bool([x])ConvertavaluetoaBoolean,usingthestandardtruthtestingprocedure.Ifxisfalseoromitted,thisreturnsFalse;otherwiseitreturnsTrue.boolisalsoaclass,whichisasubclassofint.
5、Classboolcannotbesubclassedfurther.ItsonlyinstancesareFalseandTrue布尔类型的转化用法:7.二进制数组的转化bytearray([source[,encoding[,errors]]])Returnanewarrayofbytes.Thebytearraytypeisamutablesequenceofintegersintherange0<=x<256.Ithasmostoftheusualmethodsofmutablesequences,describedinMutableS
6、equenceTypes,aswellasmostmethodsthatthestrtypehas,seeStringMethods.Theoptionalsourceparametercanbeusedtoinitializethearrayinafewdifferentways:·Ifitisastring,youmustalsogivetheencoding(andoptionally,errors)parameters;bytearray()thenconvertsthestringtobytesusingstr.encode().·I
7、fitisaninteger,thearraywillhavethatsizeandwillbeinitializedwithnullbytes.·Ifitisanobjectconformingtothebufferinterface,aread-onlybufferoftheobjectwillbeusedtoinitializethebytesarray.·Ifitisaniterable,itmustbeaniterableofintegersintherange0<=x<256,whichareusedastheinitialcont
8、entsofthearray.Withoutanargument,anarrayofsize0iscreated.8.callable(object)