TypeError: min() takes 1 positional argument but 2 were given
- User
TypeError: min() takes 1 positional argument but 2 were given
- Assistant
The error
TypeError: min() takes 1 positional argument but 2 were givenoccurs when themin()function is called with more arguments than it can accept. Themin()function is designed to take either a single iterable (like a list or a tuple) or two or more individual values. If it is being used incorrectly, this error can arise.Here are a few scenarios where this error can occur and how to fix them:
-
Single Iterable: If you're passing a single iterable, make sure you pass it correctly:
# Incorrect usage result = min([3, 1, 2], 4) # This raises the error # Correct usage result = min([3, 1, 2]) # This works: returns 1 -
Multiple Arguments: If you want to find the minimum between two or more values, just call with those values separated by commas:
-