Two standardized input methods commonly used in Python: sys.stdin and input respectively. The two methods of use are roughly the same, but in general, the use of sys.stdin To be more diverse, the following examples illustrate the differences between the two.
1. Input input
Input input is very simple, just get User input is usually in the console interface.
After running, you can wait for user input. Eventually, the system will consider the Enter key to end the input.
2. sys.stdin input
First, it can also achieve the same function as input, such as
However, it is more commonly used in another way. You can directly use the file as the overall input, which can be easily concise.
#Usage method, it is very convenient to redirect the file to the input.
The above is the detailed content of How to read stdin in Python. For more information, please follow other related articles on the PHP Chinese website!