Functions Intermediate, Step 1 Error?

I am receiving a TypeError: ‘str’ object is not callable when I write my code - hand-typed but copies, but when I copy/past the answer provided, I have the correct answer? I just do not see the differences, and am hoping someone could briefly point out why I’m erroring?

My Code:

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

Output

TypeErrorTraceback (most recent call last)
<ipython-input-1-fb0dc62600a0> in <module>()
      1 a_list = [1, 8, 10, 9, 7]
----> 2 print(max(a_list))
      3 def max(a_list):
      4     return 'No max value returned'
      5 

TypeError: 'str' object is not callable

Dataquest Answer and Code

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

Output

No max value returned

You may have assigned/bounded the name of the built-in max function to a string, so now max does not refer to the max() you think it is but a string.
Here’s a longer explanation: TypeError: 'x' object is not callable

2 Likes

Thanks! I have read over the link you provide! It was really helpful but did not solve my problem. I reported it to DQ and it looks like I somehow was running into a glitch.

Nonetheless, I appreciate your help - the provided article helped to shed the light on other questions I had.