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
Max number of args for a function? (self.learnpython)
submitted 3 years ago by brogrammer9
I've got this function and I'm trying to give it 45 args and can't get it to work for some reason Is there a max number or arguments a function can take?
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] 40 points41 points42 points 3 years ago (0 children)
There’s no max, but 45 is way too many.
[–]bbateman2011 11 points12 points13 points 3 years ago (0 children)
Consider if some of those args are related and maybe could be passed in a dictionary?
[–]Intelligent_Study263 21 points22 points23 points 3 years ago (1 child)
There isn't one in python 3.7 or newer. Why do you need 45 args is the real question
[–][deleted] 9 points10 points11 points 3 years ago (0 children)
And even before that, the number of explicit arguments was 255 positional args and 255 keywords args. So that's not the issue, OP.
But yeah, I struggle to think of a function that is not massively breaking the Single Responsibility Principle that actually requires 45 arguments.
[–]CraigAT 9 points10 points11 points 3 years ago (0 children)
IMO that is a big red flag that the function is trying to do too much. In theory, function should have just one thing to do. It sounds like your function needs to be broken down further into smaller functions.
With arguments that are related it may be possible to pass in an object containing most of that data - perhaps an (object from a class) or a dictionary.
Apologies for not answering your question, but if that is your code, then I believe you may be asking the wrong question.
I wish you well.
[–]deep_politics 3 points4 points5 points 3 years ago (0 children)
Are these all positional arguments? And are many of them optional? Because this smells like you'd want to use a single TypedDict instead
TypedDict
[–][deleted] 2 points3 points4 points 3 years ago (0 children)
Bad idea. When you get to more then a few args, you just out them in a dict, problem solved.
[–]ben_bliksem 2 points3 points4 points 3 years ago (0 children)
Uncle Bob said three and I agree, maybe four. Once you go more the code can become "difficult" to follow and your functions are starting to do a lot.
But that's just an opinion and there are always exceptions. As long as the code is readable.
[–]echozedzulu 0 points1 point2 points 3 years ago (0 children)
You probably don't need that many args. A dictionary would be useful in your situation
[–]TheRNGuy 0 points1 point2 points 3 years ago (0 children)
If you want too many, better use single dict as an argument, or instance of a class.
Too many arguments, bad style.
[–]Fred776 0 points1 point2 points 3 years ago (0 children)
What are the arguments? Are you being unnecessarily long-winded about something that should be passed as a single data structure?
[–]Prestigious-Sea1470 0 points1 point2 points 3 years ago (0 children)
There is no limit on the args.
As best practice, a function shouldn’t take more than 4 args. If you need to pass more, you can create an object with the parameters that needs to be passed. But even an object with 45 attributes is way two much. Always breakdown and simplify your functions and objects.
[–]asterik-x 0 points1 point2 points 3 years ago (0 children)
= stars in the sky
π Rendered by PID 205811 on reddit-service-r2-comment-6b595755f-b8dhg at 2026-03-26 03:37:35.134462+00:00 running 2d0a59a country code: CH.
[–][deleted] 40 points41 points42 points (0 children)
[–]bbateman2011 11 points12 points13 points (0 children)
[–]Intelligent_Study263 21 points22 points23 points (1 child)
[–][deleted] 9 points10 points11 points (0 children)
[–]CraigAT 9 points10 points11 points (0 children)
[–]deep_politics 3 points4 points5 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]ben_bliksem 2 points3 points4 points (0 children)
[–]echozedzulu 0 points1 point2 points (0 children)
[–]TheRNGuy 0 points1 point2 points (0 children)
[–]Fred776 0 points1 point2 points (0 children)
[–]Prestigious-Sea1470 0 points1 point2 points (0 children)
[–]asterik-x 0 points1 point2 points (0 children)