Python Lessons – 1.6 Input and Output

Python Lessons - 1.6 Input and output

Output

Often during the execution of a program, it is necessary to bring back some text strings (output) on the console. You have already seen that the print() function is used to correctly report a string or a variable.

>>> print ( "Hello World!")
Hello World!

Input

Sometimes it may be necessary to manually enter a value during the execution of a program (input), and for this operation the input() function can be used. This function will make a flashing cursor appear at the request of the value.

>>> input ("Enter your name: ")
Enter your name: Fabio
'Fabio'

These functions do not seem very useful when you are working with the Python console, in fact in this case it is superfluous to use these commands, because the input and output operation are implied in interaction with the console. But Python is a programming language, in which sometimes programs are also composed of thousands of lines of code, and during this execution it will often be necessary to interact with the program either by displaying for example the results (output) or by entering values to operate choices (input).

⇐ Go to Python Lesson 1.5 – Strings

Go to Python Lesson 1.7 – Operations on strings ⇒

Leave a Reply