After input(), then Python waits for the user to enter input and press Enter, or to cancel with Ctrl+D.

On macOS and Linux, this seems to use the readline shell command internally.


From help(input):

Help on built-in function input in module builtins:

input(prompt=None, /)
    Read a string from standard input.  The trailing newline is stripped.
    The prompt string, if given, is printed to standard output without a
    trailing newline before reading input.
    If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError.
    On *nix systems, readline is used if available.


Example in the CLI:

>>> answer = input()
Hello, World!
>>> answer
'Hello, World!'

Or as a script:

answer = input()

Example with a prompt. Note the space after the prompt text.

>>> answer = input("What is your age? ")
What is your age? 31
>>> answer
>>> int(answer)

Put the question and answer on different lines using \n and tell the user to enter input with > symbol.

>>> input("What is your age?\n> ")
What is your age? 
> 31

Here is a REPL. It runs in a loop, handling user input and printing repeatedly.

print("Square tool")

while True:
  answer = input("Enter a number:\n> ")
  squared = int(answer) ** 2
  print(f"Squared: {squared}\n")

Running it:

$ python3 app.py
Enter a number:
> 2
Squared: 4

Enter a number:
> 4
Squared: 16

Deprecation note

Note that previously there was both and input and raw_input. Using input would evaluate input as Python code using something like eval internally. This turned for example numeric input from a string to an integer.

Now there is just input. This is safe and will not run an evaluation as Python code.

Get password


Note the prompt is included. And the characters entered will get masked as invisible text.

getpass.getpass(prompt='Password: ', stream=None) 


import getpass 
    p = getpass.getpass() 
except Exception as error: 
    print('ERROR', error) 
    print('Password entered:', p) 

Running it. Using **** to show characters that will be entered but invisible.

$ python3 app.py
Password: ****
Password entered: abcd