I want to write program that check args. Do annotations are use for this purpose? actually what dose annotations do ?
def bar(x: str ) -> int:
return 12.5
but I can put a int to x and return a float!! so what annotations do ?
>>> bar(12)
12.5
>>>
I know for checking arg I can use :
style1:
def foo(x: str ):
if type(x)==str:
return 0
else :return (-1)
to do this by annotations :
def foo(string : str) -> str:
if foo.__annotations__.get('string')==type(string):
print('continue...')
that mean annotations does not force args ?! so why do not use style1 ? actually I want to know that annotations do in simple terms ?