1

I'm relatively new to python, and in my learning venture, I've seen a lot of this in my learning venture:

list_name.sort(key=…, reverse=…)

I don't quite understand why, in some functions, they create a variable within the function, rather than simply entering the number, Boolean, string, etc.

I have a working theory on why this is done, but I'd like some reassurance on this.

My assumption is that declaring the variable within the function call has no effect on the execution of the call. Effectively, it is the same as simply entering the value into the call, but provides better clarity on the use of the function.

I believe my understanding is correct, but I haven't seen it written anywhere and I'd love some reassurance.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
foxrumor
  • 29
  • 3
  • https://www.google.com/search?q=python+named+and+positional+arguments – ipaleka Jun 27 '19 at 21:14
  • Thank you for clarifying this. I knew I was misunderstanding something here. – foxrumor Jun 27 '19 at 21:15
  • For reference, look at the arguments you can pass in to the sklearn [decisiontreeclassifier](https://scikit-learn.org/stable/modules/generated/sklearn.tree.DecisionTreeClassifier.html) (though this is technically an object, not a function) and you can see why you would want to pass in named arguments rather than just positional (if you want to pass some but not all, or pass them in a different order) – G. Anderson Jun 27 '19 at 21:17
  • 2
    Knowing what something is called works wonders on figuring out what it does. – foxrumor Jun 27 '19 at 21:23

0 Answers0