Borislav Hadzhiev
Wed Apr 20 2022·2 min read
Photo by Jan Valečka
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.
Here is an example of how the error occurs.
w = 'name' # ⛔️ TypeError: input expected at most 1 argument, got 3 s = input('Your ', w, ': ')
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.
w = 'name' s = input('Your ' + w + ': ') print(s)
The addition (+) operator can be used to concatenate strings.
print('a' + 'b' + 'c') # 👉️ 'abc'
An alternative approach is to use a formatted string literal.
w = 'name' s = input(f'Your {w}: ') print(s)
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.
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.
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.