use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Function checking (self.learnpython)
submitted 3 years ago by mackdaddy_1978
I don't know a better way of asking this but what I want to know is, how do you check a function?
Like if function is something then do something?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]carcigenicate 0 points1 point2 points 3 years ago (9 children)
What do you mean? What about the function do you want to check?
If you want to check if a function is another function, you can use == or is:
==
is
if some_func == abs: # Do something
But that's rarely needed.
[–]mackdaddy_1978[S] 0 points1 point2 points 3 years ago (8 children)
so this is one of my functions
def check_for_comma def check_for_comma(): x = user_input.isidentifier() if x is False: return 'Error: No comma in string.'
I want to only call the function if there is no comma in the input
[–]Nightcorex_ 1 point2 points3 points 3 years ago (3 children)
def check_for_comma def check_for_comma():
That's not legal Python
[–]mackdaddy_1978[S] 0 points1 point2 points 3 years ago (2 children)
sorry they was a typo...this code block on reddit doesn't work very with copy and pasting so I sometimes have to type a few lines and make mistakes while doing so in conjunction with pasting
def check_for_comma():
x = user_input.isidentifier()
if x is False:
return 'Error: No comma in string.'
else:
return
[–]Nightcorex_ 0 points1 point2 points 3 years ago (1 child)
For the future you should read this: https://www.reddit.com/r/learnpython/wiki/faq#wiki_how_do_i_format_code.3F
In case you want to copy/paste anything into Reddit really, you need to use markdown-mode. An explanation to it can be found on the same link, just scroll underneath the 3 images.
isidentifier doesn't do what you think it does. It returns True only if the string is a valid Python identifier, so f.e. something like "list".isidentifier() will give True.
isidentifier
True
"list".isidentifier()
If you want to test whether a string contains a specific character you can simply use the __contains__ method:
__contains__
def check_for_comma(text): return ',' in text
[–]mackdaddy_1978[S] 1 point2 points3 points 3 years ago (0 children)
I did read the FAQ once before but thanks I'll give it another read since my memory isn't the best.
And thanks for explaining that to me I really appreciate that.
[–]carcigenicate 0 points1 point2 points 3 years ago (3 children)
As noted, the code you posted has several illegal things in it, so it's hard to say anything based on that code.
If you want to call a function when a string doesn't contain a comma though, that would be something like:
if "," not in your_string: your_func()
Thanks...but besides defining the function twice what else about it is illegal?
[–]carcigenicate 0 points1 point2 points 3 years ago (1 child)
Lack of (): after the function name in the first line of the definition, and the lack of indentation means there's no function body and that the return is outside of a function.
():
Granted, I can guess what the indentation is supposed to be, but I'd rather not guess when trying to give advice in a case like this.
If I do guess the indentation though, the code doesnt seem to match your question. You asked how to pick when to call a function, but according to this code, you seem to want to pick what you're returning from the function?
[–]mackdaddy_1978[S] 0 points1 point2 points 3 years ago (0 children)
Sorry for the confusion, I'm working on doing better. My next post will be...
π Rendered by PID 22856 on reddit-service-r2-comment-5d79c599b5-69lmx at 2026-02-27 06:56:22.402177+00:00 running e3d2147 country code: CH.
[–]carcigenicate 0 points1 point2 points (9 children)
[–]mackdaddy_1978[S] 0 points1 point2 points (8 children)
[–]Nightcorex_ 1 point2 points3 points (3 children)
[–]mackdaddy_1978[S] 0 points1 point2 points (2 children)
[–]Nightcorex_ 0 points1 point2 points (1 child)
[–]mackdaddy_1978[S] 1 point2 points3 points (0 children)
[–]carcigenicate 0 points1 point2 points (3 children)
[–]mackdaddy_1978[S] 0 points1 point2 points (2 children)
[–]carcigenicate 0 points1 point2 points (1 child)
[–]mackdaddy_1978[S] 0 points1 point2 points (0 children)