Jul-23-2019, 11:56 AM
(Jul-23-2019, 02:48 AM)leodavinci1990 Wrote: I want to enter 1 and return a data type class <int> for example or the same with list, float, dict
It is hard to tell a computer what you mean when typing 1. It may be a char (in case of python -- a string of len 1),
integer value (as you want), and float value too (1 belongs to the set of real number); or even something else, we can
imagine that it is a complex number
1+i0
. However, input
is used to enter some characters from keyboard, so it looks natural that input
returns a string. However, you can override its default behavior, e.g.
_input = input def input(q): x = _input(q) # if x consist only of digits, it is likely should be integer, # lets convert it to integer and return it # if x consist of digits and has e, E, +, -, or dot, that might be a float (this should be clarified) # lets convert it to float and return it # and so on... # if no condition were satisfied return result as is. return x