What does -> do in python? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What does -> do in python?

For example how does it effect the code down below? def f(x) -> int: return x print(f(12.3))

24th Dec 2018, 2:08 PM
Juho Pesonen
Juho Pesonen - avatar
1 Answer
+ 5
It's an annotation that the function should return an integer. In your example, it will return a float. That's a bit misleading but technically okay because the interpreter will just ignore these annotations.
24th Dec 2018, 2:22 PM
Anna
Anna - avatar