0

I known the python defined two type method arguments:

  1. position arguments
  2. keyword arguments

and position arguments can divided into three types:

  1. plain position arguments
  2. default arguments
  3. variable arguments

Similarly, the keyword arguments divided below three types:

  1. optional (keyword) arguments
  2. named keyword arguments
  3. plain keyword arguments

So, I defined a method:

def method(a, b=1, *c, d = 'default', e, **f)
    print(a, b, c, d, e, f)

I have some confusion:

  1. In the calling method, whether can use the keyword arguments for position arguments, such as:

    method(b=2, a=1, c=[1,2,3], e=4)

  2. I think the default parameters can replace named keyword, but why introduce optional (keyword) arguments?

  3. My understanding is there a problem?

artzok
  • 151
  • 1
  • 8
  • 4
    When learning code, the most important thing is to try things out. Actually write code, run it, see what happens, tinker and experiment. I promise **this will answer all your questions here very quickly**. Only reading theory will hamper your learning hugely. – Alex Hall Mar 26 '17 at 14:20
  • 1
    http://stackoverflow.com/questions/1419046/python-normal-arguments-vs-keyword-arguments – dabadaba Mar 26 '17 at 14:20
  • 1
    Also there's plenty of documentation: for example, [the PEP that introduced keyword-only arguments](https://www.python.org/dev/peps/pep-3102/), which explains *why* they were added too. – jonrsharpe Mar 26 '17 at 14:24
  • about your question 2, what if you don't want to supply a default and still want a value for the argument? – Shiping Mar 26 '17 at 14:27
  • Thank you for your advice, I've been running the code, but the more I write, the more confused. So I hope to find a very clear summary. – artzok Mar 26 '17 at 14:30

0 Answers0