0
I am not able to understand what the return statement do-true and false do here .can someone explain the same with example .
def dun(word,required): for letter in required: if letter not in word: return false return true
2 Respostas
0
This is a function with two parameters. The function is called somewhere in the program, does its thing then the result is passed back to the caller with the return statement. Example call:
has_letter = dun('hello', 'ho')
So the function cycles though all the letters of the 'required' parameter. If any of those letters is not found in the 'word' then the return value is False (and the function execution stops).
If all the letters are found then the for loop finished and the value True is returned.
In the end the return value is assigned to the variable (called 'has_letter' in my example)
0
True and False are boolean keywords in Python.
The number 0 and an empty list [] are also considered equal to False