+ 2
Is it possible to have a input() be able to take a string or integer.
How would I be able to have an input be able to have a string or integer entered without changing the statement type (str/int/etc).
6 Respuestas
+ 5
input()n will always bring in a string because the function doesn't know what someone might type in. You just have to convert it to whatever you need. This gives you control over error handling / exception handling.
+ 2
You would have to overwrite the function with your own implementation that can return an integer or other misc appropriate data type.
Python's built in function assumes string, always.
0
U can a = str(input(" hdhdvd"))
0
I am shocked honestly.. OP didn’t ask to make the input() function specifically work like that.
If you lack in knowledge at least don’t speak and lie to people.
There is a way, simple and efficient.
You def a func that takes input like the built in input() func and you check with it. The output can be adjusted to suit your needs.
You call it and it takes an input like the built in input().
https://sololearn.com/compiler-playground/cYkDw241vySU/?ref=app
I wrote this for you, check it.
You write it once, after that just call the function and you have both the type and the value set to the proper data type, ready to use.
0
Hi
0
45 web page create