CS61A UC Berkeley

Function

Names,Assignment,and User-Defined Function

  1. 1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    >>> g=max
    >>>max(1,2)
    2
    >>>g(1,2)
    2
    >>>max=1
    >>>max
    1
    >>>max(1,2)
    Traceback (most recent call last):
    File "<pyshell#17>", line 1, in <module>
    >>>max(1,2)
    TypeError: 'int' object is not callable
    >>>g(1,2)
    2

Environment Diagrams