So I have a basic understanding of why this is occurring but would like a detailed explanation of this.
In the Introduction to Python, Functions: Intermediate - Step 1/12 when using the delete keyword, If the variable max_val_test_0
is printed after the created function max
is deleted how come it still prints No max value returned
instead of 10
in the output?
It’s it seems that max_val_test_0
can still store the value from the deleted max
function since it is assigned the created function within the creation (define) and deletion of the created function. Below is an example:
a_list = [1, 8, 10, 9, 7]
print(max(a_list))
def max(list_name):
return 'No max value returned'
max_val_test_0 = max(a_list)
print(max_val_test_0)
print(max(a_list))
del max
print(max_val_test_0)
print(max(a_list))
max_val_test_0 = max(a_list)
print(max_val_test_0)
print(max(a_list))
Here is the output from the executed code:
10
No max value returned
No max value returned
No max value returned
10
10
10