[Tutor] Python type annotation question
Arup Rakshit
ar at zeit.io
Mon Jun 24 14:48:02 EDT 2019
I am little experimenting with Python type annotation today. I wrote a simple class as below:
>>> from datetime import date
>>> class Person:
... dob: date
... def __init__(self, dob):
... self.dob = dob
...
>>> Person(11)
<__main__.Person object at 0x10e078128>
>>> p = Person(11)
>>> p.dob
11
Although I marked dob as date type, why am I able to assign it an int? So my question how does type annotation helps, when should we use them and what advantages it brings?
Thanks,
Arup Rakshit
ar at zeit.io
More information about the Tutor
mailing list