python 知识点

来源:互联网 发布:java使用md5加密解密 编辑:程序博客网 时间:2024/05/16 09:47

【1】filter(function or None, iterable) --> filter object

filter(lambda x : x%2, [1,2,3,4,5]) --> [1,3,5]

【2】map(func, *iterables) --> map object

map(lambda x : x*2,  range(5)) --> [0,2,4,6,8]

【3】dict初始化方式 3种

dict() -> new empty dictionary

 |  dict(mapping) -> new dictionary initialized from a mapping object's
 |      (key, value) pairs
 |  dict(iterable) -> new dictionary initialized as if via:
 |      d = {}
 |      for k, v in iterable:
 |          d[k] = v
 |  dict(**kwargs) -> new dictionary initialized with the name=value pairs

 |      in the keyword argument list.  For example:  dict(one=1, two=2)

【4】issubclass(cls, class_or_tuple, /)

Return whether 'cls' is a derived from another class or is the same class

【5】isinstance(obj, class_or_tuple, /)

    Return whether an object is an instance of a class or of a subclass thereof.注意:当第一个参数需传入对象实例,而不能传入class,否则结果都为false,第二个参数需传入类,否则会抛出异常。


原创粉丝点击