Test Your Knowledge: Quiz

 

 
  1. What is the output of the following code, and why?

    >>> def func(a, b=4, c=5):
    ...     print(a, b, c)
    ...
    >>> func(1, 2)

    广告:个人专属 VPN,独立 IP,无限流量,多机房切换,还可以屏蔽广告和恶意软件,每月最低仅 5 美元

  2. What is the output of this code, and why?

    >>> def func(a, b, c=5):
    ...     print(a, b, c)
    ...
    >>> func(1, c=3, b=2)

  3. How about this code: what is its output, and why?

    >>> def func(a, *pargs):
    ...     print(a, pargs)
    ...
    >>> func(1, 2, 3)

  4. What does this code print, and why?

    >>> def func(a, **kargs):
    ...     print(a, kargs)
    ...
    >>> func(a=1, c=3, b=2)

  5. One last time: what is the output of this code, and why?

    >>> def func(a, b, c=3, d=4): print(a, b, c, d)
    ...
    >>> func(1, *(5,6))

  6. Name three or more ways that functions can communicate results to a caller.