How to explicitly specify the type of the variable passed to the class constructor?

How do I explicitly specify the type of the transferred variable in the constructor?
For example:
class A:
def __init__(self, height):
how do I make it so that I knew exactly what height will go value of type fleet
April 3rd 20 at 17:40
3 answers
April 3rd 20 at 17:42
Right in the arguments when declaring the function in any way. Only inside the function can writeheight = float(height)
April 3rd 20 at 17:44
No way. Python doesn't know static typing. But you can make some approximations:
1. mypy + typing will make Python a semblance TypeScript
2. typing. Your IDE (if normal) will tell you that you will pass is not float. But the runtime of such checks, as in paragraph number 1
3. Raise an error if if not isinstance(height, float). The check only works in runtime IDE nothing podsvetit
April 3rd 20 at 17:46
Make your kastelic:
class A:
 def __init__(self, height: float):
 if not isinstance(height, float):
 raise Exception('the height is not float type!')

Find more questions by tags Python