Home  >  Article  >  Backend Development  >  How to read stdin in Python

How to read stdin in Python

silencement
silencementOriginal
2019-05-23 16:17:226058browse

How to read stdin in Python

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.

How to read stdin in Python

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

How to read stdin in Python

However, it is more commonly used in another way. You can directly use the file as the overall input, which can be easily concise.

How to read stdin in Python

#Usage method, it is very convenient to redirect the file to the input.

How to read stdin in Python

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:what is python torchNext article:what is python torch