Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to implement input and output by Python

Shulou Source: shulou.com Published: 2022-06-01 20:00:36 09月23日 Update

This article will explain in detail how Python implements input and output, Xiaobian thinks it is quite practical, so share it for everyone to make a reference, I hope you can gain something after reading this article.

input() input

Python provides the input() built-in function to read a line of text from standard input, which is the keyboard by default. input can take a Python expression as input and return the result.

Please enter: Gas station on the code You entered: Gas station on the code

Execution inputs:

Please enter: Code on the gas station You enter: Code on the gas station print() Output

print() function. If you want more variety in the output, you can format the output value using str.format(). See more examples below;

Hello, pythonHello, python'Hello, python' constant PI is approximately 3.141592653589793. I and you pay attention to [gas station on the code] to learn python together Pay attention to [gas station on the code], enter python to get the value of the learning guide constant PI is approximately 3.14. The value of the constant PI is approximately 3.142. 00012-003.14

Output:

Hello, pythonHello, python'Hello, python' constant PI is approximately 3.141592653589793. I and you pay attention to the code on the gas station together to learn python attention to the code on the gas station, enter python to get the value of the learning guide constant PI is approximately 3.14. The value of the constant PI is approximately 3.142. 00012-003.14pprint() Output

print() and python print () are both python print modules with basically the same function.

The only difference is that the data structure printed by the pprint() module is more complete, each line is a data structure, which is more convenient to read the printout. Especially for very long data printing, print() output results are in one line, inconvenient to view, and pprint() uses branch print output, so for data structure is more complex, data length is longer, suitable for pprint() printing mode.

Print() is usually used.

import pprintdef main(): data = ( "this is a string", [1, 2, 3, 4], ("more tuples", 1.0, 2.3, 4.5), "this is yet another string" ) pprint.pprint(data)if __name__ == "__main__": main()

Output;

('this is a string',[1, 2, 3, 4],('more tuples', 1.0, 2.3, 4.5), 'this is yet another string') About "Python how to achieve input and output" This article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it for more people to see.

Tags: Input output gas station constant data content function data structure more article structure result one line learning guide guide standard module learning yes complex Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Apple Shulou Information vpn macOS