DEV Community

Cover image for User Input() and Outputs
Lisa Ghosn
Lisa Ghosn

Posted on

User Input() and Outputs

User input() is an interactive function that allows the user to insert a value into your program.

An Output is the resulting data produced from the input.
print() is an example of an output function. It is used so the program can display the resulting data and/or communicate with the user.

Let's create the code for the photo banner above, as a user input example:


name = input('PLEASE ENTER YOUR NAME')
message = f'HELLO {name}! AND WELCOME!'
print(message)
Enter fullscreen mode Exit fullscreen mode

The program has asked for John's name in order to communicate a welcome message to him.

There are implicit and explicit data type conversions in python. Inputs will always produce a string unless otherwise stated, this is an implicit (automatic) conversion.

If you would like an input to produce a different data type, it will need to be explicitly instructed, for example;
age = int(input()) - will convert the input into an integer.
We can check data types with the type() function;
print(type(age)) - will check what data type the value in your variable is.

Other examples of implicit and explicit conversions:

/ will implicitly produce a float and // will implicitly produce an integer. Also, math operations between an integer and a float will always produce a float.


Top comments (0)