Python programs give errors while accepting the inputs where it has to be type converted. If there is a provision to declare the input type say int input, float input and then accepting input so that compiler knows it before hand what type of input it is, and don’t generate the errors in actual run ,it will save a lot of time
Python is an interpreted language - which means: there is no compiler but just an interpreter.
If you are searching for static (before runtime) type checking, have a look into the topic “type hints”, e.g.:
If you are looking for dynamic (at runtime) type (and range) checking, have a look into:
Python’s type model does not work that way, and there are no plans to
change the compiler to check types at compile-time.
Languages that strictly check types at compile-time are called “static
“dynamic typing” – types are checked at run-time. The Python compiler
has very little information available about types, and for simplicity,
it ignores most of the information it does have. For example, even
something obviously wrong to a human will compile fine:
>>> import dis >>> code = compile('None + 23', '', 'eval') >>> dis.dis(code) 1 0 LOAD_CONST 0 (None) 2 LOAD_CONST 1 (23) 4 BINARY_ADD 6 RETURN_VALUE
It is the interpreter, not the compiler, that has access to all the type
information. All the compiler does is to produce byte-code from the
source code, and a few very simple optimizations like constant folding.
If you want a form of optional static type checking, you will need to
install third-party tools like Mypy. Some linters like Jedi also include
To learn more about Python’s optional type annotations, see the PEP: