0
def call(val = ['a']):
    print val
    val.append("b")
    return val

The output of the above function if run many times is confusing. Somehow it is reusing the value of val set in previous execution. According to me the output should be: ['a', 'b'] each time.

Executing the function

Ankit Mahajan
  • 516
  • 7
  • 17
  • 1
    Read from [here](https://stackoverflow.com/documentation/python/228/functions/972/defining-a-function-with-optional-mutable-arguments#t=201707041104437596892) – Ahsanul Haque Jul 04 '17 at 11:06
  • 1
    Good explanation: http://python-guide-pt-br.readthedocs.io/en/latest/writing/gotchas/ – Johannes Jul 04 '17 at 11:07

0 Answers0