In python, if a function doesn't have a return statement, what does it return?

python, python-3.x

Solution

If a function doesn't specify a return value, it returns `None`.

In an if/then conditional statement, `None` evaluates to False. So in theory you could check the return value of this function for success/failure. I say "in theory" because for the code in this question, the function does not catch or handle exceptions and may require additional hardening.

Problem

Given this example function: ``` def writeFile(listLine,fileName): '''put a list of str-line into a file named fileName''' with open(fileName,'a',encoding = 'utf-8') as f: for line in listLine: f.writelines(line+'\r\n') return True ``` Does this `return True` statement do anything useful? What's the difference between with it and without it? What would happen if there were no return function?

Original source

Related problems