logoalt Hacker News

boxedtoday at 6:19 AM1 replyview on HN

You think so but then you write a function with a default argument pointing to some variable that is a list and now suddenly the semantics of that are... what?


Replies

codesniktoday at 6:40 AM

you could just treat argument initialization as an executable expression which is called every time you call a function. If you have a=[], then it's a new [] every time. If a=MYLIST then it's a reference to the same MYLIST. Simple. And most sane languages do it this way, I really don't know why python has (and maintain) this quirk.