PYTHON INPUT


PYTHON INPUT

Up until now, our codes were static. The value of variables was initially defined or hardcoded into the source code.

Syntax for the input() function is:

          input[ prompt  ]

Python gives various built-in functions, but we can also create other functions for a code. And these are readily available to all of us at the Python prompt.
To provide flexibility, Python allows you to get input from the user only. And for this, we have the input() function in Python to enable us. 
The python input() takes a line from the input, then converts it into a string and returns the value.

The method of input() reads one optional argument

  • prompt (optional):- A string is written to approved output without tracking newline.

Return any value from input()

The input() method takes a line from the user, converts the line into a string by eliminating the tracking newline, and returns it.
If the mentioned prompt is a string, we can display it on the screen. In the program, if the entered value is a string, not a number. We can convert this into a number by using int() or float() functions.
You can call this function to ask the program to stop and wait for the user to enter the data. In Python 2 version, we have a built-in function raw_input(); on the other hand, in Python 3 version, we have the input() function. The program will continue when the user pushes the ENTER or RETURN key.

Example Code

var = input('Enter a prime number: ') print(var)

OUTPUT

Image Not Found