1
>>> a = [1,2,3,4,5]

Max function gives TypeError: 'int' object is not callable

>>> max(a)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'int' object is not callable
>>> max(1, 2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'int' object is not callable
>>>
2
  • 5
    My bet is that you have defined a variable called max before. Commented Feb 26, 2016 at 9:43
  • check this 1() you will get the same error. Because max is shadowed by a int variable you created as bereal stated. Commented Feb 26, 2016 at 9:46

3 Answers 3

1

The error is clear: you have redefined max to be an int in your code. Or you use someone else's code that does that. So you probably have something like this somewhere

max = 4

This is why it is seen as very bad practice to use built-in names as variable names. Python allows you to do it, but it's error prone.

Prefer the use of maximum or max_ if you really want something close to max.

Sign up to request clarification or add additional context in comments.

Comments

0

It works:

In [1]: a = [1,2,3,4,5]

In [2]: max(a)
Out[2]: 5

If you have not shadowed max somewhere, everything works as expected.

Comments

0

You have somewhere in your code defined a variable named max

max = something

Because:

a = [1,2,3,4,5]
print max(a)

Outputs 5 and works perfectly.

1 Comment

Exactly. Works fine. I had another variable named max. My bad. This is embarrasing

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.