0

Is my annotations are correct ? What is correct way or syntax to create annotations in functions ?

# This is my first annotation code in python. #I don't know completely how to put annotation in function. def f(ham_or_spam: str, eggs: list=[]) -> int: print("Annotations:", f.__annotations__) if ham_or_spam == 'spam' and eggs: return 'This is a spam' elif ham_or_spam == 'ham' and eggs: return 'This is a ham' else: return 'This is not a ' + ham_or_spam print(f('spam',True)) print(f('spam'))

4th Jun 2021, 3:15 AM
lisa
1 Respuesta
+ 1
I'm not quite sure what this function is about, but it seems to return a string, so shouldn't it be "-> str"?
6th Jun 2021, 2:01 PM
Lisa
Lisa - avatar