DEV Community

Discussion on: Let's Talk Python - Some of the Unknown 👤

Collapse
 
taikedz profile image
Tai Kedzierski

All these are new to me - but most quizzical is the default mutable object. I had to parse that in my head several times before I could quite grasp its implications.

It's as if

def thing(a = []):
  a.append("nope")
Enter fullscreen mode Exit fullscreen mode

is processed in-interpreter as

  • define a = <an array>
  • assign a to address <$A>
  • define thing using <$A>

So some sort of pre-processing of assignments ...

Which is essentially what you explained but I just really needed to express it in my own broken break-down....

I have never tried to use such a construct, but I am pretty sure I have seen it in some peoples' code at work so I will endeavour to weed that out.....!

I am englihtened!

Collapse
 
siddharth2016 profile image
Siddharth Chandra

Glad you found it interesting 😊

And the disaster that's blessing in disguise is to use this for logging within a function. Capture some kind of information everytime a function is called.

There are sure some more interesting ways to log our findings or errors, like using decorator, singleton object or mutable objects in functions and simply using conditionals.