📅 2012-May-04 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ function, none, python ⬩ 📚 Archive
This will seem odd to programmers from other languages. In Python, a function that has no return statement or an exit path in the function that has no return statement actually returns None. So, a variable can be used assign the return value of such functions. This also means that one does not need to worry about every exit path in the function. In languages like C, such behaviour would be a compilation error.
def foo( x ):
print( x )
= foo( 10 )
y
if y is None:
print( "foo returned None" ) # Printed
else:
print( "No, it did not!" )
Tried with: Python 3.2