For the first time a friend of the Python programming language, just beginning to learn Python programming for
input and output in PythonThis aspect of the understanding is relatively small, in this article we will come to understand
python input and outputRelated knowledge.
Output
You can output the specified text to the screen by using print () to enclose the string in parentheses. For example, the output of ' Hello, world ', implemented in code as follows:
>>> print (' Hello, World ')
The print () function can also accept multiple strings, separated by a comma "," to connect to a string of outputs:
>>> print (' The quick brown fox ', ' Jumps over ', ' the Lazy Dog ') The "quick brown fox jumps over the" the Lazy Dog
Print () prints each string sequentially, encounters a comma "," and outputs a space, so the output string is spelled like this:
Print () also prints integers, or calculates the result:
>>> print (300>>>) print (100 + 200) 300
Input
Now you can use print () to output the results you want. But what if you want users to enter some characters from the computer? Python provides an input () that allows the user to enter a string and store it in a variable. For example, enter the user's name:
>>> name = input () Michael
When you enter name = input () and press ENTER, the python interactive command line is waiting for your input. At this point, you can enter any character and then press ENTER to complete the input.
Once the input is complete, there is no hint, and the Python interactive command line is back to >>>. So where is the content we just entered? The answer is stored in the name variable. You can enter name directly to view variable contents:
>>> name ' Michael
In short, any computer program is to perform a specific task, with the input, the user can tell the computer program required information, with the output, the program can be run to tell the user the results of the task.
Inputs are input and outputs are output, so we refer to the input and output collectively as input/output, or abbreviated to IO.
Input () and print () are the most basic inputs and outputs below the command line, but the user can also complete the input and output through other more advanced graphical interfaces, such as entering their name in a text box on a webpage, and clicking "OK" to see the output on the page.