TypeError: 'X' expected at most 1 argument, got 2 [Solved]

avatar
Borislav Hadzhiev

Last updated: Apr 8, 2024
5 min

banner

# Table of Contents

  1. TypeError: TUPLE expected at most 1 argument, got 2
  2. TypeError: INPUT expected at most 1 argument, got 3
  3. TypeError: LIST expected at most 1 argument, got 2 in Python

# TypeError: tuple expected at most 1 argument, got 2

The Python "TypeError: tuple expected at most 1 argument, got 2" occurs when we pass multiple arguments to the tuple() class.

To solve the error, pass an iterable, such as a list containing the arguments.

typeerror tuple expected at most 1 argument got 2

Here is an example of how the error occurs.

main.py
# โ›”๏ธ TypeError: tuple expected at most 1 argument, got 2 my_tuple = tuple('a', 'b')

The tuple class takes at most 1 argument - an iterable.

# Passing multiple values in a list to the tuple() class

We can pass multiple values in a list to the tuple class.

main.py
my_tuple = tuple(['a', 'b']) print(my_tuple) # ๐Ÿ‘‰๏ธ ('a', 'b') print(my_tuple[0]) # ๐Ÿ‘‰๏ธ 'a' print(my_tuple[1]) # ๐Ÿ‘‰๏ธ 'b'

pass multiple values in list to tuple class

Python indexes are zero-based, so the first item in a tuple has an index of 0, and the last item has an index of -1 or len(my_tuple) - 1.

# Creating a tuple that has lists as elements

If you need to create a tuple containing lists as items, pass a two-dimensional list to the tuple() class.

main.py
my_tuple = tuple([['a'], ['b']]) print(my_tuple) # ๐Ÿ‘‰๏ธ (['a'], ['b'])

create tuple that has lists as elements

Tuples are very similar to lists, but implement fewer built-in methods and are immutable (cannot be changed).

# How tuples are constructed in Python

Tuples are constructed in multiple ways:

  • Using a pair of parentheses () creates an empty tuple
  • Using a trailing comma - a, or (a,)
  • Separating items with commas - a, b or (a, b)
  • Using the tuple() constructor

# Tuples are immutable

Note that tuples are immutable, so if you have to mutate a sequence, you have to use a list instead.

main.py
my_list = ['a', 'b', 'c'] print(my_list) # ๐Ÿ‘‰๏ธ ['a', 'b', 'c'] my_list.append('d') print(my_list) # ๐Ÿ‘‰๏ธ ['a', 'b', 'c', 'd'] my_list.insert(0, 'z') print(my_list) # ๐Ÿ‘‰๏ธ ['z', 'a', 'b', 'c', 'd'] print(my_list[0]) # ๐Ÿ‘‰ 'z'

tuples are immutable

Note that lists are created using square brackets.

The list.append() method adds an item to the end of the list.

The method returns None as it mutates the original list.

If you need to add an item at a specific index, use the insert() method.

The list.insert() method inserts an item at a given position.

The method takes the following 2 parameters:

NameDescription
indexThe index of the element before which to insert
itemThe item to be inserted at the given index

# Table of Contents

  1. TypeError: INPUT expected at most 1 argument, got 3
  2. TypeError: LIST expected at most 1 argument, got 2 in Python

# TypeError: input expected at most 1 argument, got 3

The Python "TypeError: input expected at most 1 argument, got 3" occurs when we pass multiple arguments to the built-in input() function.

To solve the error, use a formatted string literal to concatenate the arguments into a single string.

typeerror input expected at most 1 argument got 3

Here is an example of how the error occurs.

main.py
w = 'name' # โ›”๏ธ TypeError: input expected at most 1 argument, got 3 s = input('Your ', w, ': ')
The input() built-in function expects at most 1 argument, so we have to concatenate the arguments into a single string.

# Use the addition (+) operator to solve the error

One way to solve the error is to use the addition (+) operator to concatenate the strings.

main.py
w = 'name' s = input('Your ' + w + ': ') print(s)

The addition (+) operator can be used to concatenate strings.

main.py
print('a' + 'b' + 'c') # ๐Ÿ‘‰๏ธ 'abc'

# Using a formatted-string literal to solve the error

An alternative approach is to use a formatted string literal.

main.py
w = 'name' s = input(f'Your {w}: ') print(s)
Formatted string literals (f-strings) let us include expressions inside of a string by prefixing the string with f.

Make sure to wrap expressions in curly braces - {expression}.

This solves the error because we are passing a single, string argument to the input() function.

The input() function takes an optional prompt argument and writes it to standard output without a trailing newline.

main.py
s = input('Your name: ') print(s)

The function then reads the line from the input, converts it to a string and returns the result.

An alternative to providing the prompt argument is to use calls to the print() function.

main.py
print('Your name: ') s = input() print(s)

This is very similar to passing the prompt argument to the input() function but instead of showing the prompt on the same line, it is displayed on a separate line.

# TypeError: list expected at most 1 argument, got 2 in Python

The Python "TypeError: list expected at most 1 argument, got 2" occurs when we pass multiple arguments to the list() class which takes at most 1 argument.

To solve the error, use the range() class to create a range object or pass an iterable to the list() class.

typeerror list expected at most 1 argument got 2

Here is an example of how the error occurs.

main.py
# โ›”๏ธ TypeError: list expected at most 1 argument, got 2 my_list = list(0, 5)

The list() class expects to get called with at most 1 argument - an iterable.

main.py
my_tuple = ('a', 'b', 'c') my_list = list(my_tuple) print(my_list) # ๐Ÿ‘‰๏ธ ['a', 'b', 'c']

# Creating a range of integers

If you meant to create a range of integers, use the range() class.

main.py
my_list = list(range(0, 5)) print(my_list) # ๐Ÿ‘‰๏ธ [0, 1, 2, 3, 4]

And if you meant to create a list containing multiple items, pass the items in an iterable in the call to the list() class.

main.py
my_list = list(['a', 'b', 'c']) print(my_list) # ๐Ÿ‘‰๏ธ ['a', 'b', 'c']

The list class takes an iterable and returns a list object.

The range() class is commonly used for looping a specific number of times in for loops and takes the following parameters:

NameDescription
startAn integer representing the start of the range (defaults to 0)
stopGo up to, but not including the provided integer
stepRange will consist of every N numbers from start to stop (defaults to 1)

If you only pass a single argument to the range() constructor, it is considered to be the value for the stop parameter.

main.py
for n in range(5): print(n) result = list(range(5)) # ๐Ÿ‘‡๏ธ [0, 1, 2, 3, 4] print(result)
The example shows that if the start argument is omitted, it defaults to 0 and if the step argument is omitted, it defaults to 1.

If values for the start and stop parameters are provided, the start value is inclusive, whereas the stop value is exclusive.

main.py
result = list(range(1, 5)) # ๐Ÿ‘‡๏ธ [1, 2, 3, 4] print(result)

If the value for the stop parameter is lower than the value for the start parameter, the range will be empty.

main.py
result = list(range(1, 0)) # ๐Ÿ‘‡๏ธ [] print(result)

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.

Copyright ยฉ 2025 Borislav Hadzhiev