Solve - TypeError: input expected at most 1 argument, got 3

avatar

Borislav Hadzhiev

Wed Apr 20 20222 min read

banner

Photo by Jan Valečka

Solve - 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.

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'

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 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.

Use the search field on my Home Page to filter through my more than 1,000 articles.