My function returns None, Python 3
Question:
I am not too sure why this returns None, it worked perfectly before I tried putting it into a function. It is supposed to return a list of words that are between 6 and 9 characters long.
def level_list(minn, maxx):
for words in word_list:
if len(words) >= minn and len(words) <= maxx:
return level_words.append(words)
print(level_list(6, 9))
Answers:
list.append
is a mutator method, meaning that unlike string methods which return the modified version of the string, this directly changes the list and returns None
.
More about:
I am not too sure why this returns None, it worked perfectly before I tried putting it into a function. It is supposed to return a list of words that are between 6 and 9 characters long.
def level_list(minn, maxx):
for words in word_list:
if len(words) >= minn and len(words) <= maxx:
return level_words.append(words)
print(level_list(6, 9))
list.append
is a mutator method, meaning that unlike string methods which return the modified version of the string, this directly changes the list and returns None
.
More about: