News for hackers. Stuff that matters.
Re:A few things to remember while coding in Python by chernevik on Sunday May 20, 2012 @08:46PM (#4000753)
I'm a little confused about this as an assignment to a variable. Is that because of the 'return' omission referred to below? If all function f did was return x, I could see how this works with a 'return' prepended.

But if this expression is a line in a larger function, and is intended to reset the value of argument x if no other value is passed in for it, does this really act as an assigment to x? Because I sort of read this expression as evaluating to some value -- the passed value for x, or a [] -- but does this assign that value to the argument x? Or must it be x = [expression]

Re:A few things to remember while coding in Python by coderdude on Sunday May 20, 2012 @11:37PM (#4001150)

  def f(x=None):
        x = x if x is not None else []
        return x
Now it will assign that value back to x. Otherwise it would just evaluate the expression.
Re:A few things to remember while coding in Python by chernevik on Monday May 21, 2012 @06:00AM (#4002086)
Thanks for the additional clarity.