To read input from the console (stdin), you can use the input()
function in Python 3.x or raw_input()
function in Python 2.x. These functions read input as a string until a newline character is encountered.
Here's an example code block to read input from console:
main.py75 chars3 lines
Alternatively, you can use sys.stdin.readline()
to read input from the console in a Python script:
main.py93 chars5 lines
In this example code, rstrip('\n')
is used to remove the newline character at the end of the input string, as readline()
includes the newline character in the returned string.
gistlibby LogSnag