Python

从这个 builtins.py(model)中我们能学到什么

2018-06-06  本文已影响193人  月蚀様

模块、包、库、框架的区别

Python中 *args 和 **kwargs 的区别

在浏览这个模块的时候,经常可以看见函数的形参为 args 或*kwargs,那么这一小节我们来总结一下这两者之前的区别

可变长度参数:*args 和 **kwargs

def func(arg, *args, **kwargs):
      print(arg, *args, **kwargs)
func(6, 7, 8, 9, 10, a=2, b=8, c=10)

输出结果:
6 (7, 8, 9, 10) {'a':2, 'b':8, 'c':10}

Functions 函数

1. abs()
Return the absolute value of the argument

2. all()
Return True if bool(x) is True for all values x in the iterable(可迭代对象). If the iterable is empty, return True

>>> from collections import Iterbale
>>> isinstance('abcde', Iterable)
True
>>> isinstance([1,2,3], Iterable)
True
>>> isinstance((1,2,3), Iterable)
True
>>> isinstance({'abcde':2}, Iterable)
True

3. any()
Return True if bool(x) is True for any x in the iterable. If the iterable is empty, return False

4. ascii(object)
Return an ASCII-only representation of an object.
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. This generates a string similarto that returned by repr() in Python 2.

5. bin(), oct(), hex()

上一篇下一篇

猜你喜欢

热点阅读