景观设计师如何做网站,帮别人做ppt挣钱的网站,网站开发实训总结致谢,正规的网页设计公司“专业人士笔记”系列目录#xff1a;创帆云#xff1a;Python成为专业人士笔记--强烈建议收藏#xff01;每日持续更新#xff01;zhuanlan.zhihu.com模块是一个包含Python定义和语句的文件#xff0c;而函数是执行逻辑的一段代码 。要检查python中内置的函数#xff…“专业人士笔记”系列目录创帆云Python成为专业人士笔记--强烈建议收藏每日持续更新zhuanlan.zhihu.com模块是一个包含Python定义和语句的文件而函数是执行逻辑的一段代码 。要检查python中内置的函数可以使用dir()。如果调用的时候不带任何参数则返回当前范围中的名称。否则返回一个按字母顺序排列的名称列表其中包含(一些)给定对象的属性以及从中可以访问的属性。尝试运行如下命令显示所有函数dir(builtins)
输出
[ArithmeticError,AssertionError,AttributeError,BaseException,BufferError,BytesWarning,DeprecationWarning,EOFError,Ellipsis,EnvironmentError,Exception,False,FloatingPointError,FutureWarning,GeneratorExit,IOError,ImportError,ImportWarning,IndentationError,IndexError,KeyError,KeyboardInterrupt,LookupError,MemoryError,NameError,None,NotImplemented,NotImplementedError,OSError,OverflowError,PendingDeprecationWarning,ReferenceError,RuntimeError,RuntimeWarning,StandardError,StopIteration,SyntaxError,SyntaxWarning,SystemError,SystemExit,TabError,True,TypeError,UnboundLocalError,UnicodeDecodeError,UnicodeEncodeError,UnicodeError,UnicodeTranslateError,UnicodeWarning,UserWarning,ValueError,Warning,ZeroDivisionError,debug,doc,
import,name,package,abs,all,any,apply,basestring,bin,bool,buffer,bytearray,bytes,callable,chr,classmethod,cmp,coerce,compile,complex,copyright,credits,delattr,dict,dir,divmod,enumerate,eval,execfile,exit,file,filter,float,format,frozenset,getattr,globals,hasattr,hash,help,hex,id,input,int,intern,isinstance,issubclass,iter,len,license,list,locals,long,map,max,memoryview,min,next,object,oct,open,ord,
pow,print,property,quit,range,raw_input,reduce,reload,repr,reversed,round,set,setattr,slice,sorted,staticmethod,str,sum,super,tuple,type,unichr,unicode,vars,xrange,zip
]要了解任何函数的功能及属性我们可以使用内建函数帮助方法是命令运行help(函数名)比如help(max)
输出Help on built-in function max in module builtin:max(…)max(iterable[, keyfunc]) - valuemax(a, b, c, …[, keyfunc]) - value在单个可迭代参数中返回其最大的项。使用两个或多个参数返回最大的参数。 而内建模块则包含一些额外的函数。例如为了得到一个数字的平方根我们需要包括数学(math)模块 import mathmath.sqrt(16) # 输出4.0 为了了解模块中的所有函数我们可以将函数名称分配给一个变量然后打印该变量。import math
print(dir(math))
输出 [doc, name, package, acos, acosh,asin, asinh, atan, atan2, atanh, ceil, copysign,cos, cosh, degrees, e, erf, erfc, exp, expm1,fabs, factorial, floor, fmod, frexp, fsum, gamma,hypot, isinf, isnan, ldexp, lgamma, log, log10,log1p, modf, pi, pow, radians, sin, sinh, sqrt,tan, tanh, trunc]除了函数之外还可以在模块中提供文档。如果你有一个像这样的名为helloWorld.py的文件 这是模块内函数的定义.def sayHello():这是模块内函数的代码return Hello World您可以像这样访问它 import helloWorldhelloWorld.__doc__这是模块的描述helloWorld.sayHello.__doc__这是函数的描述 对于所有用户定义的类型都可以使用dir()来检索其属性、类的属性以及递归地检索其类的基类的属性比如创建一个class类class MyClassObject(object):pass我们来检索它的定义dir(MyClassObject)
输出[class, delattr, dict, doc, format, getattribute, hash,init, module, new, reduce, reduce_ex, repr, setattr,sizeof, str, subclasshook, weakref]任何数据类型都可以使用名为str的内置函数简单地转换为字符串。在将变量传递给print时默认情况下都会调用该函数 比如str(123)#输出 123因为默认的print打印都会转成Str字符串打印到屏幕今天分享就到这里禁止任何形式转载违者必究