+ 6

Do you know about return type in python?

please describe me how to work "return type" in python

29th Nov 2017, 12:18 AM
Kulanga Kaushani
Kulanga Kaushani - avatar
1 Answer
+ 4
Assuming you are referring to the return type of Python functions... Functions in Python don't technically have a return type. Okay, well, they do, but you don't need to specify it, unlike other languages. For example: def f(num): result = 1 for count in range(1, num+1): result *= count return result Here, it is implied the return type is int, considering result is an int and it's type is not changed. Or, you could do this: def f(num): result = "1" for count in range(1, num+1): result *= count return result The return type is now a string, because result is a string, and it is returned, hence the return type is a string. That about sums it up. Hope this helped. 😉
29th Nov 2017, 12:40 AM
blackcat1111
blackcat1111 - avatar