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. 数据持久化以及DAO模式的简单使用

    持久化:(是将程序中的数据在瞬时状态和持久状态间转换机制)        即把数据(如内存中的对象)保存到可永久保存的存储设备中(如磁盘).持久化的主要应用是将内存中的对象存储在关系型的数据库中,当然 ...

  2. 使用XSHELL连接EC2虚拟机实例

    sudo passwd root #输入2次密码给root用户设定密码 su - passwd ec2-user #输入两次密码给ec2-user用户设定密码 sed -ri 's/^#?(Passw ...

  3. [TCPIP] 分层 Note

    TCP/IP  分层 TCP/IP是一组不同层次上的多个协议的组合. 通常被分为:链路层.网络层.运输层.应用层 1. 链路层(数据链路层 或 网络接口层) 通常包括操作系统中的设备驱动程序和计算机中 ...

  4. c++多线程のunique和lazy initation

    unique更方便使用,但是会消耗更多的计算机性能 onceflag保证一个线程被调用一次,防止不能的加锁开锁

  5. uwsgi出现invalid request block size: 21573 (max 4096)...skip解决办法

    buffer-size uwsgi内部解析的数据包大小,默认4k. 如果准备接收大请求,你可以增长到64k. 允许uwsgi接收到32k,更大的会被丢弃. xweb.ini [uwsgi]socket ...

  6. js跨域访问,No 'Access-Control-Allow-Origin' header is present on the requested resource

    js跨域访问提示错误:XMLHttpRequest cannot load http://...... No 'Access-Control-Allow-Origin' header is prese ...

  7. selenium定位元素(本内容从https://my.oschina.net/flashsword/blog/147334处转载)

    注明:本内容从https://my.oschina.net/flashsword/blog/147334处转载. 在使用selenium webdriver进行元素定位时,通常使用findElemen ...

  8. Linux and the Device Tree

    来之\kernel\Documentation\devicetree\usage-model.txt Linux and the Device Tree ----------------------- ...

  9. Freemarker中日期时间格式出错

    今天遇到一个奇怪的问题.同事访问我电脑发布的程序页面,freemarker日期格式报错.而其他电脑访问则没有问题. 先贴出错误信息. FreeMarker template error The str ...

  10. angularjs指令系统系列课程(2):优先级priority,模板template,模板页templateUrl

    今天我们先对 priority,template,templateUrl进行学习 1.priority 可取值:int 作用:优先级 一般priority默认为0,数值越大,优先级越高.当一个dom元 ...