So Ai-chan was looking at documentations of python and Ai-chan found these words args kwargs a lot. Those who are good with python, can you tell Ai-chan what these are and how to use them? Ai-chan googled but still can't understand. Sounds too much like chocobo gibberish. Like can't people just put stuff like achievement.register(name, **kwargs) into achievement.register(name, textvariableorwhatever)? Why put something so strange?
Say you have a function: def foo(animal,owner,leash,*args,**kwargs): pass (indents don't seem to work on NUF) Then if you call foo(cat,John,None,"lazy cat",1,name="Garfield"), the normal (named?) arguments (animal, owner, leash) get values cat, John and None respectively. The args are "lazy cat" and 1, put into the args list in that order, and name="Garfield" is a kwarg (key word argument?). So you get a list called args and a dict called kwargs. I think. It's been some time. Edit: the names can be changed if you want, just keep the order(?) and the asterisks the same. I think the Python devs took that over from C. (A few similarities with argc/argv for main, but no real C/C++ equivalent.) It's a way to sort of ... pass through generic arguments to a function?
They are used to pass variable number of arguments or keyword arguments to functions when you don't know how many arguments there will be at the time the function is defined. For example, you could put args in a tuple and kwargs in a dict and prepend the variable names with *s in function call. my_args = (1, 2, 3) my_kwargs = {"arg0": 6, "arg1": 4} my_func(*my_args, **my_kwargs) Edit: I think this is a good post about this: https://pythontips.com/2013/08/04/args-and-kwargs-in-python-explained/
Oh shit. I thought you were looking on Python documentaries. Turns out it something about programming, lol.
You can usually find this stuff right away from a google search, not that it matters. It would be faster for you to search them this way since I'm sure you'll have many more questions to come.
That's a good remark, it's not very interesting figuring out why they don't just do a Google search though.
WinByDying's explanation was the easiest and most understandable i have seen. Usually in the programming questions forums they do not give such foolproof answers, or at least rarely do so.
Several reasons why they might have done such a thing, takeaway however is that it's actually much easier (for them) to do a quick google. The analogy is like this: You're sitting in a chair and there's a bowl of chips in front of you. You want chips, all you have to do is reach out and take them! But instead, you get up off your chair, search around the house, find somebody and ask them if they could come to the living room and grab some chips for you. Much more effort than it's worth, most of the time - unless you're trying to socialize.
WinByDying has a good explanation for what they do. If you are asking why take a look at str.format() it allows users to put arbitrary variables into the function to produce meaningful output. In addition it serves as way to do the opposite of *list or **dict (expansion) for functions and gather the items. Also stackoverflow is your friend for questions like this.
kwargs (keyword args) are dictionary keywords being passed to a function as a parameter. StackOverflow is your friend: https://stackoverflow.com/questions...to-a-function-in-python-as-keyword-parameters For more on dictionary use in Python: https://www.tutorialspoint.com/python/python_dictionary.htm
I spent the last few minutes just staring and reading the posts trying to figure out what they were on about with programming language before my sleep deprived brain finally remembered that Python is not only a type of snake but a programming language. I feel like a tired moron.
I mean if you actually read what @Ai chan said in her OP, you'd realize she did try to google it and she couldn't understand their explanations.
Oh I read it. And I don't believe her. Not that I think she's doing anything wrong, I was just giving some advice as I believe that unless you're dealing with something truly abstract, usually at a high level (which she obviously is not at, given the context), you can find many well-explained, documented and exampled responses online.
No offense, but frequently for the novice programmer, which I'm pretty sure she is, online help is incomprehensible. They explain things as if they assume you are very much familiar with the language in question and with programming. And while I'm sure after reading a bunch of articles and slowly piecing it together, she could figure it out, she has no desire to be a programmer in and of itself. She's not trying to figure out the language, but how to simply and practically use it. And generally online help isn't optimized to do that.
This is where we disagree then. Like I stated earlier, my comment was a suggestion made with her best interest in mind, not a decree from the heavens - and yes, I made the suggestion with the assumption that she's a beginner. She can do w/e she wants.