In python, a function would return None
either explicitly or implicitly.
e.g.
# Explicit
def get_user(id):
user = None
try:
user = get_user_from_some_rdbms_byId(id)
except:
# Our RDBMS raised an exception because the ID was not found.
pass
return user # If it is None, the caller knows the id was not found.
# Implicit
def add_user_to_list(user):
user_list.append(user) # We don't return something, so implicitly we return None
A python function would return 0
either because of some computation:
def add_2_numbers(a,b):
return a + b # 1 -1 would return 0
Or because of a magic
flag kind of thing, which is frowned upon.
But in python we don't use 0
to denote success because this:
if get_user(id):
would not evaluate to True
if we returned 0
therefore this if
branch would not run.
In [2]: bool(0)
Out[2]: False