Python provides two built-in functions to read a line of text from standard input, and the default standard input is the keyboard. As follows:
1.raw_input
2.input
Raw_input function
The Raw_input () function reads a line from the standard input and returns a string (minus the end of the newline character):
Copy the Code code as follows:
str = raw_input ("Enter Your input:");
Print "Received input is:", str
This will prompt you to enter any string and then display the same string on the screen. When I enter "Hello python! ", its output is as follows:
Copy the Code code as follows:
Enter your Input:hello Python
Received input Is:hello Python
Input function
The input () function and the raw_input () function are basically interchangeable, but input assumes that your input is a valid Python expression and returns the result of the operation. This should be the biggest difference between the two.
Copy the Code code as follows:
str = input ("Enter your input:");
Print "Received input is:", str
This will produce the following results for the input:
Copy the Code code as follows:
Enter your input: [x*5 for X in range (2,10,2)]
Recieved input is: [10, 20, 30, 40]