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
#2
Please use bbtags when posting code.

hello is a string and needs to be 'hello' as well as the letter 'h'

Example:
def contains_letter(string, letter):
    for letters in string:
        if letters == letter:
            return True
    return False

print(contains_letter('hello', 'h'))
output
Output:
True
buran likes this post
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
Download my project scripts


Reply


Messages In This Thread
RE: Variable is not defined error when trying to use my custom function code - by menator01 - Nov-23-2023, 08:40 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  not able to call the variable inside the if/elif function mareeswaran 3 543 Feb-09-2025, 04:27 PM
Last Post: mareeswaran
Question Variable not defined even though it is CoderMerv 3 1,817 Mar-28-2024, 02:13 PM
Last Post: Larz60+
  Variable for the value element in the index function?? Learner1 8 2,884 Jan-20-2024, 09:20 PM
Last Post: Learner1
  Printing the variable from defined function jws 7 7,279 Sep-03-2023, 03:22 PM
Last Post: deanhystad
  Function parameter not writing to variable Karp 5 2,111 Aug-07-2023, 05:58 PM
Last Post: Karp
  Badly defined python code? Ken76 2 1,423 May-25-2023, 11:05 PM
Last Post: DigiGod
  Getting NameError for a function that is defined JonWayn 2 2,101 Dec-11-2022, 01:53 PM
Last Post: JonWayn
Question Help with function - encryption - messages - NameError: name 'message' is not defined MrKnd94 4 5,242 Nov-11-2022, 09:03 PM
Last Post: deanhystad
  How to print the output of a defined function bshoushtarian 4 2,253 Sep-08-2022, 01:44 PM
Last Post: deanhystad
  Retrieve variable from function labgoggles 2 1,791 Jul-01-2022, 07:23 PM
Last Post: labgoggles

Forum Jump:

User Panel Messages

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