-1
def auto_detect_serial_unix(preferred_list=['*']):

What happens to the argument when this function gets called?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Eddison
  • 7
  • 3
  • You need to read [the Python tutorial](https://docs.python.org/3/tutorial/controlflow.html#default-argument-values). – BrenBarn Jul 18 '16 at 03:30
  • Possible duplicate of [Default Values for function parameters in Python](http://stackoverflow.com/questions/13195989/default-values-for-function-parameters-in-python) – OneCricketeer Jul 18 '16 at 03:30

2 Answers2

0

If nothing is passed in to auto_detect_serial_unix, then preferred_list is set to ['*']. Otherwise, what you pass in is set to preferred_list:

>>> def auto_detect_serial_unix(preferred_list=['*']):
...     print preferred_list
... 
>>> auto_detect_serial_unix()
['*']
>>> auto_detect_serial_unix(['new', 'list'])
['new', 'list']
>>> 
A.J. Uppal
  • 19,117
  • 6
  • 45
  • 76
0

If auto_detect_serial_unix is called with an argument, then preferred_list will have the value of that argument.

Otherwise, if auto_detect_serial_unix is called with no arguments, then preferred_list will have the given default value.

John Gordon
  • 29,573
  • 7
  • 33
  • 58