Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
def search_for_vowels():
#7
(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!
Reply


Messages In This Thread
def search_for_vowels(): - by Dixon - Jan-06-2020, 11:27 PM
RE: def search_for_vowels(): - by micseydel - Jan-07-2020, 12:38 AM
RE: def search_for_vowels(): - by Dixon - Jan-07-2020, 10:07 PM
RE: def search_for_vowels(): - by Clunk_Head - Jan-07-2020, 10:53 PM
RE: def search_for_vowels(): - by micseydel - Jan-07-2020, 11:36 PM
RE: def search_for_vowels(): - by Dixon - Jan-09-2020, 10:21 PM
RE: def search_for_vowels(): - by DeaD_EyE - Jan-10-2020, 09:17 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020