Python's function | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

Python's function

Hi, How do I know when to use a value returning function and a None function(that's a function that doesn't return value) in python codes?

3rd Mar 2018, 1:22 PM
PrinceCEE
PrinceCEE - avatar
3 Answers
+ 3
If a function doesn't return value, you cannot store with variable (in fact, you can store it although value will be always 'None'). If you wanna know whether a function/method return some value or not, check it with 'type(yourFunction())'. Note that parenthesis after your function name. If it return some value, interpreter will show <class 'SomeType'> rather than <class 'NoneType'>. Hope it helps :)
3rd Mar 2018, 1:33 PM
Sylar
+ 2
@syla, thanks for the input. I know that a None function returns None and hence the variable referencing it would be None too. But I was particularly confused as to why some functions have to be coded so that they won't return a value when actually, value is to be returned. Now, my main question is why use a None function when it doesn't return anything other than None?
3rd Mar 2018, 1:42 PM
PrinceCEE
PrinceCEE - avatar
+ 1
Think about print() which print output to console rather than returning value. (because it don't need to return anything at all) Why bother returning something if you don't need the value (i.e value which will be used for some operation).
3rd Mar 2018, 1:55 PM
Sylar