Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python3 min() and max()

On a Linux Debian 12 with Python 3.11.2,
I get this :

l = [ 1, 2, 3 ]
min(l)
1
max(l)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'int' object is not callable

Why the max() function doesn’t work ?

Thanks.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I expected that max(l) return 3

>Solution :

I think you must have reassigned the builtin max function of python, to a integer, hence creating a new max(int variable), it could have happened like this

max = 5
l = [1,2,3]
max(l)

that’s why you could have gotten the error that "int" object is not callable, you try

  1. changing you code, (not declaring a max variable)
  2. Restore the Built-in max Function:
import builtins
max = builtins.max

For more information, you can try sharing the code snippet.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading