What is difference between return 0, return 1 and return -1 in python? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is difference between return 0, return 1 and return -1 in python?

What is difference between return 0, return 1 and return -1 in python? Briefly explain what does it mean?

25th Mar 2022, 2:57 AM
Utsav Singh
Utsav Singh - avatar
6 Answers
+ 4
return is used to "return" a value from a function. That value can be anything - an integer, string or even a tuple/dictionary
25th Mar 2022, 3:12 AM
Infinity
Infinity - avatar
+ 3
return 20, return 30, return 100, return "abc", return "xyz". No difference just difference in values
25th Mar 2022, 3:17 AM
A͢J
A͢J - avatar
+ 2
Parsa Gharavi that would be a shallow understanding of `return`. What if someone defines 0 as True and 1 as False?
25th Mar 2022, 3:20 AM
Infinity
Infinity - avatar
+ 2
Infinity I know; You're right. I was just trying to explain the general idea.
25th Mar 2022, 3:23 AM
Parsa Gharavi
Parsa Gharavi - avatar
+ 1
when you return 1, you are basically returning True as the final value of the function while return 0 is basically returning False as the final value of the function. Negative 1 (-1) or any negative numbers that get returned show that the function couldn't find the output wanted (indexing).
25th Mar 2022, 3:18 AM
Parsa Gharavi
Parsa Gharavi - avatar
0
Parsa Gharavi well explained
26th Mar 2022, 9:11 PM
Malay Patra