[issue42610] Get the type from a variable
Filipe Laíns
report at bugs.python.org
Fri Dec 11 16:48:17 EST 2020
Filipe Laíns <lains at riseup.net> added the comment:
There is type() to get the runtime type.
https://docs.python.org/3/library/functions.html#type
```python
>>> foo = 1
>>> type(foo)
<class 'int'>
```
Keep in mind that in Python using type hints does not enforce anything at runtime. You can say `foo: int = 1` but `int` there is just some extra information for type checkers, like mypy, to use.
If you want the type hints, you can use typing.get_type_hints() but this is only available for modules, classes or functions, not variables.
----------
nosy: +FFY00
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42610>
_______________________________________
More information about the Python-bugs-list
mailing list