Input and Output in Python

 Input and Output - Bytesize Python

Input

The input() function is used to collect data from the user, which it can then use to conduct the rest of the program. It will wait until the user presses the enter key, signalling that they have finished typing in the answer. A  prompt can be displayed, if you insert it inside the brackets. And the prompt might also look tidier if you remember to include a space at the end of the string.

Output

The output is what is displayed on the screen. You can display an output using the print() function. You may have seen this in the 'strings in Python' page, or in some of the other tutorials. It can be used to show a combination of text and variables.





Ways to separate strings

Previously you have seen that the output has been separated by a space between the different items. However you an change this if you want, by inserting the sep='_' function. Inside the quotation marks you can insert what character you want in between items. Hyphens are common, but symbols such as + and ** can be used too. And if you wanted each item to be printed on a different line, you can put \n in between the quotation marks.

Ways to end an output

There are several ways to end an output. Even though it may seem that adding your ending to the end of your last string is simpler, the end='_' function can be used efficiently in some circumstances. Just like the sep= function, you put what you want the string to end with inside the brackets. (Top Tip: if you want to leave several lines blank at the end of a text, just add \n how many ever times you want)









Popular Posts