Explore The Print Function In Python Statements

Ever wondered why Print function has its significance? As a question crosses our minds, why use "print function()" when you can just use "function()" to get the result. What is there with this print function? The reason is because, as a function itself, print offers a number of features for its output. While you could simply run the function sum(), you indeed get the result, but that's it. Using print, you can capture the output and redirect it, since the output, by default, goes to stdout. Print also formats objects to strings, so you don't have to worry about doing that, i.e. integers and other non-string values automatically become strings, which is useful for parsing. You can also define different separators, special end-of-line characters, and (since Python 3.3) you can immediately flush the contents to output, if desired.

Hence, print gives you more options with your programs, whereas simply running a function only performs what it is "told" to do. If you wanted to recreate some of what print provides, you'd have to make the code do that explicitly, e.g. return your data as a string. 


To view or add a comment, sign in

More articles by Manav Inder Singh

Insights from the community

Others also viewed

Explore topics