input

Full name
input
Library
Built-in
Syntax

input([prompt])

Description

The input function returns the value of prompt -if it has been included as an argument to the function-, reads a line from the standard input -the keyboard, by default-, converts it to a text string and returns it as result of the function.

Parameters
  • prompt: Text to be displayed before the text input field.
Result

The input function returns a text string.

Examples

In this example we assign the text entered by the user to the texto variable:

texto = input("Introduce un texto:")
print("Has introducido el texto {}".format(texto))

Input function. Example of use

Once we enter some text and press the Enter key, the execution of the cell continues, which, in this case, prints the entered text:

Input function. Example of use

 

We can convert the input to another type. In this second example we are inviting the user to enter an integer, and the input is converted to that type (in this example we are not expecting the user to enter something else, which would raise an error):

numero = int(input("Introduce un número entero:"))
print("Has introducido el número {}".format(numero))
print(type(numero))

Input function. Example of use

 

Submitted by admin on Wed, 01/23/2019 - 14:50