How to read user input as numbers in Python
In Python 3 onwards, the input
function returns a string
type..
int
value
You can explicitly convert this into an int
type.
|
|
float
value
If you need to accept fractional components, then simply swap this out with a float
type:
|
|
map
multiple values
If you have multiple integers in a single line, then you can use map
to extract them into a list
:
|
|