INPUT AND OUTPUT IN PYTHON

INPUT AND OUTPUT IN PYTHON

In computing, input/output or I/O is the communication between an information processing system (such as a computer) and the outside world, possibly a human or another information processing system.

Inputs are the data received by the system, and outputs are the data sent from it. In almost every computer program, the user has to input some data that will be stored in computer's memory and then subsequently processed. The devices such as keyboard, mouse are input devices and are used to input data. The input data may be taken from a disk file or from another computer via a communication channel. The intermediate and final results of the computations are also stored in computer's memory.

And finally, there is need to output the results of the computations. The output can be displayed on the computer screen, stored on a disk or transmitted via a communication channel to other computer.

A program needs to interact with the user to accomplish the desired task, this is done using Input-Output facility. 

 INPUT FROM USER

A function is defined as a block of organised, reusable code used to perform a single, related action. Python has many built-in functions, you can also create your own. Python has an input function which lets you ask a user for some text input.

You call this function to tell the program to stop and wait for the user to key in the data.

Python provides two built-in functions to read a line of text from standard input, which by default comes from the keyboard. These functions are as follows.

   (1) input() 

 This function first takes the input from the user  and then evaluates the expression, which means Python automatically identifies whether user             entered a string or number or list.

If the input provided is not correct, then either syntax error or exception is raised by Python. Before input() method was not capable of handling anything other than numbers. But in Python 3, input() is capable of handing anything other than numbers like string.

Syntax 

variable_name = input (< Message to be displayed >)

Example:

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

Output:

>>> Enter your name:__________

In _________ enter his input.

OUTPUT IN PYTHON atOptions = { 'key' : '34305dce2fa4e6642bd4a2e007f54513', 'format' : 'iframe', 'height' : 300, 'width' : 160, 'params' : {} }; document.write(''); >

Output by print Statement

To output your data to the screen, use the print() function. Print evaluates the expression before printing it on the monitor. Print statement gives output an entire (complete) line and then goes to next line for subsequent output. To print more than one item on a single line, comma (,) may be used. Syntax print (expression / constant / variable) e.g. >>> print ("Arihant") Arihant >>> print (5.65) 5.65 >>> print (10 * 3) 30





Comments