Search code examples
pythonjupyterjupyter-notebook

How to give jupyter cell standard input in python?


I am trying to run a program on a jupyter notebook that accepts user input, and I cannot figure out how to get it to read standard input. For example, if I run the code with shift-enter:

a = input()
print(a)

the cell indicates it is running, but does not accept input from me. How do I get it to accept input?


Solution

  • Use the raw_input() (for Python 2) or input() (for Python 3) methods.

    Example code:

    a = raw_input()
    print(a)
    

    Example notebook: