Jeet Patel
Jeet Patel

Reputation: 1241

`__annotations__` doesn't return as expected

I was just playing around with the __annotations__ function and I tried this -

def function() -> float:

    print('I always return a `float` type data!')

the output of print(function.__annotations__) is {'return': float}.

How can I make it print {'return': <class 'float'>}

Upvotes: 0

Views: 64

Answers (1)

leaf_soba
leaf_soba

Reputation: 2518

maybe you need to update your python version.I'm using python 3.7.7,it works fine to me

code:

def function() -> float:
    print('I always return a `float` type data!')

print(function.__annotations__)

result:

{'return': <class 'float'>}

Upvotes: 1

Related Questions