Python Forum
Variable is not defined error when trying to use my custom function code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Variable is not defined error when trying to use my custom function code
#5
(Nov-23-2023, 08:40 AM)menator01 Wrote: Example:
def contains_letter(string, letter):
    for letters in string:
        if letters == letter:
            return True
    return False

print(contains_letter('hello', 'h'))

You can simply that to:

def contains_letter(string, letter):
    return bool(letter in string)
Sig:
>>> import this

The UNIX philosophy: "Do one thing, and do it well."

"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse

"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein
Reply


Messages In This Thread
RE: Variable is not defined error when trying to use my custom function code - by rob101 - Nov-23-2023, 02:53 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Variable not defined even though it is CoderMerv 3 389 Mar-28-2024, 02:13 PM
Last Post: Larz60+
  Variable for the value element in the index function?? Learner1 8 740 Jan-20-2024, 09:20 PM
Last Post: Learner1
  Printing the variable from defined function jws 7 1,440 Sep-03-2023, 03:22 PM
Last Post: deanhystad
  Function parameter not writing to variable Karp 5 1,028 Aug-07-2023, 05:58 PM
Last Post: Karp
  Badly defined python code? Ken76 2 680 May-25-2023, 11:05 PM
Last Post: DigiGod
  Getting NameError for a function that is defined JonWayn 2 1,160 Dec-11-2022, 01:53 PM
Last Post: JonWayn
Question Help with function - encryption - messages - NameError: name 'message' is not defined MrKnd94 4 2,999 Nov-11-2022, 09:03 PM
Last Post: deanhystad
  How to print the output of a defined function bshoushtarian 4 1,364 Sep-08-2022, 01:44 PM
Last Post: deanhystad
  Retrieve variable from function labgoggles 2 1,085 Jul-01-2022, 07:23 PM
Last Post: labgoggles
  User-defined function to reset variables? Mark17 3 1,714 May-25-2022, 07:22 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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