Return False or True


#1



Hi Experts,

Can you please help to figure out impact if i add True or False or don`t add to my program ?
Which one is recommended and why ?

def test(var):
if var > 5:
return True
else:
return False

test(8)

AND

def test(var):
if var > 5:
return
else:
return

test(8)


Replace this line with your code.


#2

I would recommend you write the True and False in your code for the sake of others(and yourself) being able to understand what is going on. I doubt it impacts anything like run-time but when your code gets much bigger, it's nice to see the True and False (and it reduces ambiguity).

I don't code that often in Python so sometimes when I look back, I get frustrated when my return statements just say return while trying to understand my code.

Then again, this is a question of preference. Some people like to go with the second. This is just my preference.


#3

Thank you for the answer.

I have already written number of different codes to see the difference but actually don`t see it.
That is why would be great if someone could provide why return False/True should be used.


#4

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