在有->的情況下:
def f(ham: str, eggs: str = 'eggs') -> str:
print("Annotations:", f.__annotations__)
print("Arguments:", ham, eggs)
return ham + ' and ' + eggs
f('spam')
運行結果是:
# Annotations: {'ham': <class 'str'>, 'eggs': <class 'str'>, 'return': <class 'str'>}
# Arguments: spam eggs
def f(ham: str, eggs: str = 'eggs'):
print("Annotations:", f.__annotations__)
print("Arguments:", ham, eggs)
return ham + ' and ' + eggs
f('spam')
運行結果是:
Annotations: {'ham': <class 'str'>, 'eggs': <class 'str'>}
Arguments: spam eggs
總結:
其實沒啥用,就是註釋的作用,挺花哨的功能.