I Got 99 Problems, But a Switch Ain't One


def greater_less_equal_5(answer):
if (answer>5):
print 1
elif (answer<5):
print -1
print 0

print greater_less_equal_5(4)
print greater_less_equal_5(5)
print greater_less_equal_5(6)

Output is below

So why this None is also getting printed if I am using print instead of return


You’re printing the result of calling the function, but the function has no result (None)

Most of the time a function shouldn’t be printing anything, it’s usually not part of what it promises to do. For example, it would be strange for a function which doubles numbers to also print the result out. Its job is just to double the number. Not to print it.


Thank you so much I get it :slight_smile:


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.