I'm trying to do the Javascript equivalent in Python:
a.new_func = function(arg1, arg2) {
var diff = arg1 - arg2;
return diff * diff;
}
Right now, the way I'm doing this is by defining the method first, and then assigning it, but my question is whether or not Python allows a shorthand to do the assigning and the defining part in the same line. Something like this:
a.new_func = def new_func(arg1, arg2):
diff = arg1 - arg2
return diff * diff
Instead of this:
def new_func(arg1, arg2):
diff = arg1 - arg2
return diff * diff
a.new_func = new_func
I realize the difference is not major, but am still interested to know whether or not it's possible.