sys.stdout are file objects which are used by the interpreter for standard input and standard output.
Data received by
raw_input comes from
stdin, which is normally connects to the keyboard.
stdin can be redirected
so that input instead comes from a file. This can be very useful for automating scripts.
When you call the
print(obj) function, it actually call the
sys.stdout.write(obj + '\n') like below:
import sys sys.stdout.write("hello" + "\n") print(hello)
input() function first takes the input from the user and then evaluates the expression. Python automatically identifies
whether the user entered a string or a integer or a list.
- Whatever you enter as input, input function converts it into a string.
sys.stdin.readline() reads the escape character entered by the user, like below
import sys name = sys.stdin.readline() print(name) num = sys.stdin.readline(2) print(num)
# Input Alison 'Alison\n' # Input 1234 '12'
|The input takes input from the user but doesn’t read escape character||The readline() also takes input from the user but also reads the escape character|
|It has a prompt that represents the default value before the user input||Readline has a parameter named size, which is a non-negative number, it actually defines the bytes to be read|