Built in function

My doubt is when we use a built-in function name twice(once as a built-in function and the for naming the function with using the same name) and we give “del max” which will be deleted?

In the code below the output prints " “No max value returned” twice . Does that mean the built-in function will be deleted
a_list = [1, 8, 10, 9, 7]
print(max(a_list))

def max(a_list):
return “No max value returned”

max_val_test_0=max(a_list)
print(max_val_test_0)

del max

1 Like

The latter function that you defined will be deleted.

In [1]: a_list = [*range(10)]

In [2]: max(a_list)
Out[2]: 9

In [3]: def max(a_list):
   ...:     return "No max value returned"

In [4]: max_val_test = max(a_list)

In [5]: print(max_val_test)
No max value returned

In [6]: del max

In [7]: max
Out[7]: <function max>

In [8]: max(a_list)
Out[8]: 9
1 Like

It will delete local function (user define).

Built-in max is actually __builtins__.max So it will get delete when you do

del __builtins__.max
1 Like