(Jan-06-2020, 11:27 PM)Dixon Wrote: Gives a Traceback name error when trying to invoke: "name 'search4vowels' not defined.
This happens if you call your function, before it's defined.
Example:
1 2 3 4 5 |
foo() # <- NameError! def foo(): pass |
Error:NameError: name 'foo' is not defined
This works:1 2 3 4 5 |
def foo(): pass foo() # <- Name exists and points to the memory address, where the function lives |
By the way, your code works:
1 2 3 4 5 6 7 8 9 10 11 12 |
In [ 2 ]: def search4vowels(word): ...: vowels = set ( 'aeiou' ) ...: found = vowels.intersection( set (word)) ...: for vowel in found: ...: print (vowel) ...: In [ 3 ]: search4vowels( 'Hello World' ) o e In [ 4 ]: |
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!