Skip to content

How to Resolve Python "TypeError: X expected at most 1 argument, got Y"

Fix the Python TypeError for tuple(), input(), and list() when passing too many arguments by learning the correct argument format for each constructor.

The TypeError: X expected at most 1 argument, got Y (where X is typically tuple, input, or list, and Y is greater than 1) is a common error in Python. It signifies that you've tried to call a built-in function or type constructor that accepts only zero or one argument by passing it multiple separate arguments.

This guide explains why this error occurs for tuple(), input(), and list() and provides the correct ways to pass arguments to them.

Understanding the Error: Function/Constructor Signatures

Many built-in functions and type constructors in Python have specific "signatures" defining the arguments they accept. Some, like print(), can accept a variable number of arguments. However, others, like the type constructors tuple(), list(), and the function input(), are designed to take at most one primary argument (though they might have optional keyword arguments later, that's not relevant to this specific error).

This TypeError occurs when you violate this signature by providing more than the expected number of positional arguments.

Error 1: TypeError: tuple expected at most 1 argument, got ...

Cause: Passing Multiple Arguments to tuple()

The tuple() constructor is designed to create a tuple from a single iterable argument (like a list, string, range, or another tuple). Passing multiple individual items directly causes the error.

try:
  my_tuple = tuple('a', 'b', 'c')
  print(my_tuple)
except TypeError as e:
  print(e)

Solution: Pass a Single Iterable (e.g., a List)

To create a tuple from multiple items using the tuple() constructor, enclose those items within a single iterable, most commonly a list [].

items_list = ['a', 'b', 'c']
my_tuple = tuple(items_list)

print(my_tuple)         # Output: ('a', 'b', 'c')
print(type(my_tuple))   # Output: <class 'tuple'>

my_tuple_direct = tuple(['x', 'y', 10])
print(my_tuple_direct)  # Output: ('x', 'y', 10)

The constructor now receives just one argument (the list) and correctly iterates over it to create the tuple elements.

Other Ways to Create Tuples

Remember, you often don't need the tuple() constructor to create tuples:

  • Commas: Separating items with commas automatically creates a tuple. Parentheses () are optional unless needed for clarity or grouping.
    t1 = 1, 2, 3            # Creates tuple (1, 2, 3)
    t2 = ('a', 'b', 'c')    # Parentheses are common for readability
    t3 = 'single',          # Trailing comma needed for single-element tuple
    t4 = ()                 # Empty tuple
    print(t1, type(t1))     # Output: (1, 2, 3) <class 'tuple'>
    print(t3, type(t3))     # Output: ('single',) <class 'tuple'>

Error 2: TypeError: input expected at most 1 argument, got ...

Cause: Passing Multiple Arguments to input()

The built-in input() function accepts at most one argument: an optional string to be displayed as a prompt to the user. You can not pass multiple strings or variables hoping they will be automatically joined.

user_name = "Alice"

try:
    age_str = input('Enter age for ', user_name, ': ')
    print(age_str)
except TypeError as e:
    print(e)

Solution: Concatenate or Format the Prompt String

Combine all parts of your desired prompt into a single string before passing it to input().

  • Using F-Strings (Recommended):
    user_name = "Alice"
    
    prompt_message = f"Enter age for {user_name}: "
    
    age_str = input(prompt_message)
    print(f"Input received: {age_str}")
  • Using String Concatenation (+):
    user_name = "Alice"
    
    prompt_message = 'Enter age for ' + user_name + ': '
    
    age_str = input(prompt_message)
    print(f"Input received: {age_str}")

Both methods ensure you pass only one string argument to input().

Error 3: TypeError: list expected at most 1 argument, got ...

Cause: Passing Multiple Arguments to list()

Similar to tuple(), the list() constructor expects at most one argument, which must be an iterable. You can not pass multiple individual items directly.

try:
    my_list = list('a', 'b', 'c')
    print(my_list)
except TypeError as e:
    print(f"Error 1: {e}")

try:
    my_list = list(0, 5) # Incorrect: Looks like trying to make range 0-4
    print(my_list)
except TypeError as e:
     print(f"Error 2: {e}")

Solution: Pass a Single Iterable or Use range()

  • From multiple items: Put the items inside another iterable (like a tuple () or another list []) and pass that single iterable to list().
    my_list_from_tuple = list(('a', 'b', 'c'))
    print(f"List from tuple: {my_list_from_tuple}") # Output: ['a', 'b', 'c']
    
    my_list_from_list = list(['x', 1, None])
    print(f"List from list: {my_list_from_list}")   # Output: ['x', 1, None]
    
    direct_list = ['x', 1, None]
    print(f"Direct list literal: {direct_list}")    # Output: ['x', 1, None]
  • To create a list of numbers in sequence: Use the range() function to generate the sequence and pass the range object (which is iterable) to list().
    
    number_sequence = range(0, 5)                           # Creates range(0, 5)
    my_list_from_range = list(number_sequence)
    print(f"List from range(0, 5): {my_list_from_range}")   # Output: [0, 1, 2, 3, 4]
    
    my_list_range_direct = list(range(5))                   # range(5) is equivalent to range(0, 5)
    print(f"List from range(5): {my_list_range_direct}")    # Output: [0, 1, 2, 3, 4]

Conclusion

The TypeError: X expected at most 1 argument, got Y for tuple, input, and list indicates a misunderstanding of how these functions/constructors accept arguments.

  • tuple() and list(): Expect a single iterable as input if you use the constructor. To create them from multiple elements directly, use literal syntax ((a, b) or [a, b]) or pass the elements inside another iterable (e.g., tuple(['a', 'b'])). For sequences of numbers, use list(range(start, stop)).
  • input(): Expects at most one string argument (the prompt). Combine multiple parts into a single prompt string using f-strings or concatenation before passing it to input().

You can easily avoid this common TypeError by providing arguments in the expected format, typically a single iterable for tuple()/list() and a single string for input()

Navigation