Skip to content
Advertisement

Tuple comparison in function

I am wondering why my comparison returns False and not True although 'a' == 'a'.

JavaScript

Output: False

Advertisement

Answer

It’s because you are using *values rather than values in your function definition

When you use the special syntax *args in a function, args will already come back as a tuple, where each arg is an element of the tuple.

So for example

JavaScript

In your case since you are passing in a tuple already, w/in the function values is like “Ok, I’ll happily take a tuple as my first argument”, and values becomes a tuple of tuples (well a tuple of a single tuple). Thus you are comparing (‘a’,) to ‘a’ and your check fails

TL;DR: either pass in just 'a' or change *values to values

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement