abs()
Return the absolute value of a number. The argument may be an integer or a floating point number.
If the argument is a complex number, its magnitude is returned.
返回一个数的绝对值。参数可以是整数或浮点数.。如果参数是复数,则返回它的数量级.
all(iterable)
Return True if all elements of the iterable are true (or if the iterable is empty).
返回bool,集合中所有元素不为0、''、False时返回True,若集合为空,返回True
any(iterable)
Return True if any element of the iterable is true. If the iterable is empty, return False
返回bool,当集合有任意元素为True时,返回True。集合为空或元素均为0/''/False时,返回False。
ascii()
As repr(), return a string containing a printable representation of an object, but escape the non-ASCII
characters in the string returned by repr()using \x\u or \U escapes.
bin(x)
Convert an integer number to a binary string. The result is a valid Python expression. If x is not a Python int object, it has to define an __index__() method that returns an integer.
将整数x转换为二进制字符串,结果返回一个有效的Python表达式,如果x不为Python中int类型,x必须包含方法__index__()并且返回值为integer
isinstance(object, classinfo)
Return true if the object argument is an instance of the classinfo argument, or of a (direct, indirect or virtual) subclass thereof. If object is not an object of the given type, the function always returns false. If classinfo is a tuple of type objects (or recursively, other such tuples), return true if object is an instance of any of the types. If classinfo is not a type or tuple of types and such tuples, a TypeError exception is raised.
返回bool,验证参数一是否为参数二中的类型。参数二可以为元组,参数一为元组中所属类型,返回true。
dict()
class dict(**kwarg)
class dict(mapping, **kwarg)
class dict(iterable, **kwarg)
Create a new dictionary. The dict object is the dictionary class
dict对象用来,创建字典类
map(function, iterable, ...)
Return an iterator that applies function to every item of iterable, yielding the results. If additional iterable arguments are passed, function must take that many arguments and is applied to the items from all iterables in parallel. With multiple iterables, the iterator stops when the shortest iterable is exhausted.
dir([object])
Without arguments, return the list of names in the current local scope. With an argument, attempt to return a list of valid attributes for that object. If the object has a method named __dir__(), this method will be called and must return the list of attributes. This allows objects that implement a custom __getattr__() or __getattribute__() function to customize the way dir() reports their attributes. If the object does not provide __dir__(), the function tries its best to gather information from the object’s __dict__ attribute, if defined, and from its type object. The resulting list is not necessarily complete, and may be inaccurate when the object has a custom __getattr__().
hasattr(object, name)
The arguments are an object and a string. The result is True if the string is the name of one of the object’s attributes, False if not. (This is implemented by calling getattr(object, name) and seeing whether it raises an AttributeError or not.)
判断该属性是否在对象中
setattr(object, name, value)
This is the counterpart of getattr(). The arguments are an object, a string and an arbitrary value. The string may name an existing attribute or a new attribute. The function assigns the value to the attribute, provided the object allows it. For example, setattr(x, 'foobar', 123) is equivalent to x.foobar = 123.
为对象的属性设置值
getattr(object, name[, default])
Return the value of the named attribute of object. name must be a string. If the string is the name of one of the object’s attributes, the result is the value of that attribute. For example, getattr(x, 'foobar') is equivalent to x.foobar. If the named attribute does not exist, default is returned if provided, otherwise AttributeError is raised.
获取对象属性,如果对象不存在可以设置返回默认值getattr(obj, 'attribute',default)

class type(object)
class type(name, bases, dict)
With one argument, return the type of an object. The return value is a type object and generally the same object as returned by object.__class__ The isinstance() built-in function is recommended for testing the type of an object, because it takes subclasses into account. With three arguments, return a new type object. This is essentially a dynamic form of the class statement. The name string is the class name and becomes the __name__ attribute; the bases tuple itemizes the base classes and becomes the __bases__ attribute; and the dict dictionary is the namespace containing definitions for class body and is copied to a standard dictionary to become the __dict__ attribute. For example, the following two statements create identical type objects:
>>> class X:
... a = 1
...
>>> X = type('X', (object,), dict(a=1))
只有一个参数时,返回一个新的对象类型object.__class__(即判断后的对象类型)
有三个参数时,返回一个新的对象类型,可以作为动态的创建类,X = type('X', (object,), dict(a=1))与一般定义类的方法一致。第一个参数为类X的__name__属性的值,其中第二个参数为父类,当有多个父类时需注意顺序(父类3,父类2,父类1,object),第三个参数为类属性。 同时,也可以将方法绑定到类上:
def Y(self,name='Bean'):
  print('My name is',name)
H = type('hello',(object,),dict(hello=y))

>>>h = H()
>>>h.hello()
>>>print(H.__name__)
My name is Bean
hello 
class property(fget=None, fset=None, fdel=None, doc=None)
# Return a property attribute.'返回property属性'
#fget is a function for getting an attribute value. '属性值的get方法名称'
# fset is a function for setting an attribute value. '属性值的set方法名称'
# fdel is a function for deleting an attribute value. '属性值del的方法名称'
# And doc creates a docstring for the attribute. '属性值的doc文档内容'
# A typical use is to define a managed attribute x: //使用方法定义属性及属性值的操作方法
class C:
def __init__(self):
self._x = None def getx(self):
return self._x def setx(self,value):
self._x = value def delx(self):
del self._x x = property(getx, setx, delx, 'Test Property') c = C()
c.x = 123
print(c.x)
print(C.x.__doc__)
# If c is an instance of C, c.x will invoke the getter, c.x = value will invoke the setter and del c.x the deleter.
# If given, doc will be the docstring of the property attribute.
# Otherwise, the property will copy fget‘s docstring (if it exists).
# This makes it possible to create read-only properties easily using property() as a decorator:使用装饰器模式设置属性值只读
class Parrot:
def __init__(self):
self._voltage = 100000
@property
def voltage(self):
"""Get the current voltage."""
return self._voltage
p = Parrot()
print(p.voltage)
# 使用装饰器声明和操作属性
# The @property decorator turns the voltage() method into a “getter” for a read-only attribute with the same name,
# and it sets the docstring for voltage to “Get the current voltage.”
# A property object has getter, setter, and deleter methods usable as decorators that create a copy of
# the property with the corresponding accessor function set to the decorated function.
# This is best explained with an example:
class CC:
def __init__(self):
self._x = None @property
def x(self):
"""I'm the 'x' property."""
return self._x @x.setter
def x(self, value):
self._x = value @x.deleter
def x(self):
del self._x
cc = CC()
cc.x = 123
print(cc.x)
print(CC.x.__doc__)
class CC 与Class C两种方式均可,最好使用class CC的方式
callable(object)
Return True if the object argument appears callable, False if not. If this returns true, it is still possible that a call fails, but if it is false, calling object will never succeed. Note that classes are callable (calling a class returns a new instance); instances are callable if their class has a __call__() method.
判断一个变量是对象还是函数呢。判断一个对象是否能被调用,能被调用的对象就是一个Callable对象。当能被调用时返回True,否则返回False
super([type[, object-or-type]])
Return a proxy object that delegates method calls to a parent or sibling class of type. This is useful for accessing inherited methods that have been overridden in a class. The search order is same as that used by getattr() except that the type itself is skipped.
The __mro__ attribute of the type lists the method resolution search order used by both getattr() and super(). The attribute is dynamic and can change whenever the inheritance hierarchy is updated.
If the second argument is omitted, the super object returned is unbound. If the second argument is an object, isinstance(obj, type) must be true. If the second argument is a type, issubclass(type2, type) must be true (this is useful for classmethods).
There are two typical use cases for super. In a class hierarchy with single inheritance, super can be used to refer to parent classes without naming them explicitly, thus making the code more maintainable. This use closely parallels the use of super in other programming languages.
The second use case is to support cooperative multiple inheritance in a dynamic execution environment. This use case is unique to Python and is not found in statically compiled languages or languages that only support single inheritance. This makes it possible to implement “diamond diagrams” where multiple base classes implement the same method. Good design dictates that this method have the same calling signature in every case (because the order of calls is determined at runtime, because that order adapts to changes in the class hierarchy, and because that order can include sibling classes that are unknown prior to runtime).
For both use cases, a typical superclass call looks like this:
class C(B):
def method(self, arg):
super().method(arg) # This does the same thing as:
# super(C, self).method(arg)
Note that super() is implemented as part of the binding process for explicit dotted attribute lookups such as super().__getitem__(name). It does so by implementing its own __getattribute__() method for searching classes in a predictable order that supports cooperative multiple inheritance. Accordingly, super() is undefined for implicit lookups using statements or operators such as super()[name].
Also note that, aside from the zero argument form, super() is not limited to use inside methods. The two argument form specifies the arguments exactly and makes the appropriate references. The zero argument form only works inside a class definition, as the compiler fills in the necessary details to correctly retrieve the class being defined, as well as accessing the current instance for ordinary methods.
For practical suggestions on how to design cooperative classes using super(), see guide to using super().

python3内置函数的更多相关文章

  1. python3内置函数大全(顺序排列)

    python3内置函数大全 内置函数 (1)abs(),   绝对值或复数的模 1 print(abs(-6))#>>>>6 (2)all() 接受一个迭代器,如果迭代器的所有 ...

  2. python3内置函数大全

    由于面试的时候有时候会问到python的几个基本内置函数,由于记不太清,就比较难受,于是呕心沥血总结了一下python3的基本内置函数 Github源码:        https://github. ...

  3. Python3内置函数、各数据类型(int/str/list/dict/set/tuple)的内置方法快速一览表

    Python3内置函数 https://www.runoob.com/python3/python3-built-in-functions.html int https://www.runoob.co ...

  4. python3内置函数详解

    内置函数 注:查看详细猛击这里 abs() 对传入参数取绝对值 bool() 对传入参数取布尔值, None, 0, "",[],{},() 这些参数传入bool后,返回False ...

  5. python 之 python3内置函数

    一. 简介 python内置了一系列的常用函数,以便于我们使用,python英文官方文档详细说明:点击查看, 为了方便查看,将内置函数的总结记录下来. 二. 使用说明 以下是Python3版本所有的内 ...

  6. Python3 内置函数补充匿名函数

    Python3 匿名函数 定义一个函数与变量的定义非常相似,对于有名函数,必须通过变量名访问 def func(x,y,z=1): return x+y+z print(func(1,2,3)) 匿名 ...

  7. python3 内置函数

    '''iter()和next()'''# lst = [1, 2, 3]# it = iter(lst)# print(it.__next__())# print(it.__next__())# pr ...

  8. python3 内置函数详解

    内置函数详解 abs(x) 返回数字的绝对值,参数可以是整数或浮点数,如果参数是复数,则返回其大小. # 如果参数是复数,则返回其大小. >>> abs(-25) 25 >&g ...

  9. python3 内置函数enumerate

    一.简介: 该函数在字面上是枚举.列举的意思,用于将一个可遍历的数据对象(如列表.元组或字符串)组合为一个索引序列, 同时列出数据和数据下标,一般用在 for 循环当中,可同时得到数据对象的值及对应的 ...

随机推荐

  1. 关于sql的关联排序

    个人觉得对sql的玩转其实是sql中各种函数方法的理解的透彻. 原始数据表 要求查询的结果排序 其实刚看题目可能觉得要用group by但是再网下继续思考可能就没有思路了 但是如果你接触过over的试 ...

  2. JS验证码

    1.引用jquery 2.Html页面 <div> <canvas id="canvas" style="cursor: pointer; height ...

  3. 关于bootstrap的一些运用

    bootstrap用起来很方便,代码量少,写自适应网站最合适了! 关于bootstrap你必须要知道的几点: “行(row)”必须包含在 .container (固定宽度)或 .container-f ...

  4. angular的双向数据绑定

    方向1:模型数据(model) 绑定 到视图(view) 实现方法1:{{model变量名}} $scope.num=10 <p>{{num}}</p> 实现方法2: 常用指令 ...

  5. for循环嵌套的优化

    public static void main(String[] args) {     int x = 0;     for (int i = 0; i < 2; i++) {         ...

  6. Oracle(创建index)

    概念: 1. 类似书的目录结构 2. Oracle 的“索引”对象,与表关联的可选对象,提高SQL查询语句的速度 3. 索引直接指向包含所查询值的行的位置,减少磁盘I/O 4. 与所索引的表是相互独立 ...

  7. DateEdit控件的使用

    按照年月日时分秒显示时间 1. 设置Mask.EditMask和DisplayFormat,EditFormat属性,设置为一致:'yyyy-MM-dd HH:mm';  //按照想要的显示格式设置此 ...

  8. VS.Net 2015 Update3 学习(1) 支持Webpack

    让vs.net 编译的时候自动执行webpack 首先 管理员模式下打开 “Developer Command Prompt for VS2015", 是管理员模式啊! 然后进入 cd c: ...

  9. python连接mysql的驱动

    对于py2.7的朋友,直接可以用MySQLdb去连接,但是MySQLdb不支持python3.x.这是需要注意的~ 那应该用什么python连接mysql的驱动呢,在stackoverflow上有人解 ...

  10. org.dbunit.database.ambiguoustablenameexception

    对于一个数据库下面多个shema的情况,如果使用DBUNIT配置会出现,上面的错误,不清楚的表名,解决如下 增加红色的shema指定 参考:http://stackoverflow.com/quest ...