Python: default argument blunders

A few minutes ago a friend sent me the following code, and told me its misbehaving: def foo(l=[]): l.append(“hello!”) print(l) foo() foo() Instead of printing [“hello”] twice, it printed [“hello”, “hello”]. Any ideas why? what’s going on? I’ll… Read more

Similar

How to Learn Python

Python is a mature language, easy to learn and here to stay. But where to start? We see a lot of new Pythonistas posting questions like: How to learn Python?, Where do I start?, What approach to take?. We were there once too. Now with 9 months of PyBites ... (more…)

Read more »