CKTIS / Python
function.__name__
This attribute holds a function's simple name, initially supplied by its definition.
Version: Python 3.14; repository image, production runtime not attested
Syntax
label = function.__name__This attribute holds a function's simple name, initially supplied by its definition.
function.__name__
Assigning the function to a new variable preserves that name. Setting it to another string changes no namespace binding. A lambda initially has the name <lambda>.
alias reports compute. After setting score, both names still refer to a function returning 5.
def original(): return 1
original.__name__='changed'
assert 'changed' not in globals() and original()==1
try: original.__name__=12
except TypeError: pass
else: raise AssertionError
Examples
def compute(): return 5
alias = compute
print(alias.__name__, (lambda: None).__name__)
alias.__name__ = "score"
print(compute.__name__, alias())
Result
compute <lambda> score 5
alias reports compute. After setting score, both names still refer to a function returning 5.