The difference between input and raw_input in Python is pythonraw_input.
Both input and raw_input can be used to read the input from the console, but the input and raw_input are different in processing numbers.
When the input is a pure number:
Input returns numeric values, such as int and float.
Raw_inpout returns the string type and the string type.
Input string as expression
Input calculates the number expression in the string, but raw_input does not.
For example, enter "57 + 3 ":
Input returns an integer of 60.
Raw_input will get the string "57 + 3"
Python input implementation
Read the python input document and you can see that the input is actually implemented through raw_input. The principle is very simple. The following code line is as follows:
Copy codeThe Code is as follows:
Def input (prompt ):
Return (eval (raw_input (prompt )))
What is the difference between raw_input and input in python?
You can understand this as follows:
Def input (prompt ):
& Nbspreturn eval (raw_input (prompt ))
That is to say, call the eval function to see what the input is. In fact, you can even enter an expression. Python calculates the value of the expression to return the result.
Why does a python script write raw_input () for output?
If the output is a row or a row, it is okay.
If you want to display it on the console, you must know that the displayed window disappears automatically once it is executed. Your first sentence does output Hello world in the window, but without the next sentence, the window will automatically disappear immediately, and you cannot see whether there is output. However, if raw_input () exists, the window will not disappear, because the code is not executed completely. This raw_input () requires you to enter something in the window and press enter to complete the execution, if the execution is complete, the window disappears.
Other languages have similar problems and solutions.