Reputation: 821
I understand that instrinsic names are assigned to refer to functions when these said functions refer to other functions. eg: f=max is f the intrinsic name or max?
Upvotes: 0
Views: 2601
Reputation: 1
It is better to look at the frames.
f = max
max = 3
f(2,3,4)
Global frame
f ----------------> func max(...) # object
max: 3
Notice that the function object says max. That is the intrinsic name!
Upvotes: 0
Reputation: 43
You can think of the intrinsic name as the name of user-defined def
function. Consider two ways to bind a function to a name square
:
def square(x):
return x * x
In this def
statement, both creating function and assigning name happens at the same time and this def
statement gives the function an intrinsic name. square
is "function square" here.
square = lambda x : x * x
Whereas, lambda
creates a function lambda x : x * x
without a name. The assignment statement square =
assigns the value of the function to the name. square
is "function lambda" here.
Upvotes: 1
Reputation: 22340
If you mean the __name__
property, it's the name that was used in the def
statement that created the function.
Python 3.3.1 (v3.3.1:d9893d13c628, Apr 6 2013, 20:25:12) [MSC v.1600 32 bit (In
tel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> def f ():
... return 0
...
>>> f.__name__
'f'
>>> g = f
>>> g.__name__
'f'
>>>
Built-in functions have __name__
properties matching their preset names.
>>> max.__name__
'max'
>>> h = max
>>> h.__name__
'max'
>>>
Functions that were created by some other means than a def
statement may have default values for the __name__
property.
>>> (lambda: 0).__name__
'<lambda>'
>>>
Upvotes: 6