Consciously, using DEF statements is prone to the following errors,
Reference: Exercise-25
Http://www.2cto.com/shouce/Pythonbbf/ex25.html
def add ():
Print "A True man does what he would, not what he must!"
Add () # Output print over content
A = Add () # ibid.
Print add () # Output print over content and return value
Print a # output return value, no output none
A # exists only as a variable, no output
---------------------------------------------------------------------
Excerpt from Exercise-25
def break_words (words): # def: (define) defining functions
Print Words.split (') # Remember ' to have a space, otherwise prompt error message:
Valueerror:empty Separator (delimiter)
def sort_words (words):
Print sorted (words)
TXT = "A true man does what he would, not what he must!"
List = break_words (TXT)
Sort_words (list)
ValueError: ' Nonetype ' object is not iterable (iteration)
I think this is a classic error, because Nonetype indicates that the value of the variable is empty. And the above says
Return, which is the value returned. So it should be changed. Because it's print and not return,
Returns the value, so the Nonetype appears, (the returned value is empty) is the case.
def break_words (words)
Return Words.split (")
or change list = break_words (txt) to list = Txt.split (")
def statement Common errors