
It really feels now like you are TRYING to miss the point of equality and identity, and why 'is None' checks are the correct approach to recommend. Here's a slightly contrived, but not absurd function. I've certainly written a great many that follow this general form.
def add_multiples(elements=None, multiples=None): ... if elements == None: ... # Default to the intergers 1 to 10 ... elements = list(range(1, 11)) ... if multiples == None: ... multiples = [1] * len(elements) ... total = 0 ... for e, m in zip(elements, multiples): ... total += e*m ... return total ... a = [13, 27, 52] b = [1, 2, 3] add_multiples(a, b) 223 add_multiples() 55
I was just reading something that mentioned the famous Gauss sum of sequential numbers :-). We can try this with other sequences of numbers where it should succeed (and DOES if I use the clear and obvious approach rather than deliberately confusing identity and equality):
c = np.array([13, 27, 52]) d = range(1, 1000) add_multiples(c, d) Traceback (most recent call last): File "<ipython-input-38-c4826ecd2a2e>", line 1, in <module> add_multiples(c, d) File "<ipython-input-8-8c58e2c77071>", line 2, in add_multiples if elements == None: ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()