Python – Input()

Python input() function returns a string to the assigned variable. This can cause us problems when we want to store integers or floats.

We can use the int() function to convert the string to a integer or the float() function to convert it to a floating point. It is better to do this when you get the input or initialise the variable as you may forget later in the program.

InputInt
The first block of code shows Python returning a string. The second block of code uses a int() to return an Integer

 

Leave a Reply

Your email address will not be published. Required fields are marked *