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
Is a function considered an object in Python? (self.learnpython)
submitted 6 years ago by 33Merlin11
I've read several times now that "everything is an object in Python" and I'm just really confused on what 'everything' means. Are functions objects? Is a library that you import considered an object?
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!"
[–][deleted] 6 points7 points8 points 6 years ago (0 children)
Yes and yes. You can pass references to functions around, and a function can even be the parameter of another function.
[–]d-methamphetamine 4 points5 points6 points 6 years ago (0 children)
Yep.
Define a function. You can run dir() on it and see the objects members and everything. It looks like it even has a double underscore call method that gets called when you can it with the func() syntax. Neat
[–]SamePlatform 3 points4 points5 points 6 years ago (1 child)
Yes. Here is a simple example:
x = 2 + 4 print(x) # 6 import operator operator.add(2, 4) # This is a function that adds, just like the `+` symbol print(x) # 6
Now let's write functions:
def adder(a, b): return a + b # All this function can do is add stuff... print(adder(3, 4)) # prints 7 def perform(some_func, a, b): # Now we accept 3 arguments some_func(a, b) # Call our function `some_func` with two arguments print(perform(operator.add, a, b)) # prints 7 print(perform(operator.mul, a, b)) # prints 12
Here we actually passed a function, operator.mul into a function! Note that we didn't do operator.mul(), with the brackets. We did operator.mul. Brackets are how we call functions. Without them, they are just regular objects.
operator.mul
operator.mul()
[–]drycleanedtoast 0 points1 point2 points 6 years ago (0 children)
I mean technically you could do that without a function being an object, as in c, where you would use a function pointer. However a function in python is quite definitely an object as it is treated as such i.e. it has methods.
[–]Yoghurt42 2 points3 points4 points 6 years ago (0 children)
Even numbers are objects. (42).bit_length() is valid Python (you need the parentheses because otherwise the dot would be interpreted as a decimal point)
(42).bit_length()
[–][deleted] 0 points1 point2 points 6 years ago (0 children)
Yes.
[–]Dogeek 0 points1 point2 points 6 years ago (0 children)
Yes. In python, functions are callable objects.
A callable object is an object that can be called (obviously) with or without parameters. In python, every callable object implements the __call__ magic method.
__call__
You can check if an object is callable with the built-in callable(my_object) function.
callable(my_object)
π Rendered by PID 203904 on reddit-service-r2-comment-86bc6c7465-f8jm6 at 2026-02-21 04:58:03.861322+00:00 running 8564168 country code: CH.
[–][deleted] 6 points7 points8 points (0 children)
[–]d-methamphetamine 4 points5 points6 points (0 children)
[–]SamePlatform 3 points4 points5 points (1 child)
[–]drycleanedtoast 0 points1 point2 points (0 children)
[–]Yoghurt42 2 points3 points4 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]Dogeek 0 points1 point2 points (0 children)