0
Python multiple types in input
Given that the undefined input() function can identify its type of data, why doesn't it work? https://code.sololearn.com/cywbW7uszJz3/?ref=app
2 Respostas
+ 3
It is working fine, it is just that the first condition will never become True because input() takes input as string by default.
For example I input 42:
The program will take the input like this:
"42"
That is why the type is always str-data-type.
- - - - - - - -- - - - - - -
Or if what you're trying to do is to know if the input is a number.
Then you can use .isdigit() method.
"42".isdigit()
>> True
- - - - - - - - - - - - - -
You can also use try-except for this:
For example:
try:
int(value)
print(" int data-type ")
except ValueError:
print("Not int data type")
+ 1
It finally worked.《 Nicko12 》Thanks a lot.