0

I got this from the fractions module:

if type(a) is int is type(b):

And as far as I can tell this does the same as:

if type(a) == int == type(b):

But I don't really get how those "chained" is really work, or what's their use when (imo) == looks more readable. Here's the full function

def gcd(a, b):
    """Calculate the Greatest Common Divisor of a and b.

    Unless b==0, the result will have the same sign as b (so that when
    b is divided by it, the result comes out positive).
    """
    import warnings
    warnings.warn('fractions.gcd() is deprecated. Use math.gcd() instead.',
                  DeprecationWarning, 2)
    if type(a) is int is type(b):
        if (b or a) < 0:
            return -math.gcd(a, b)
        return math.gcd(a, b)
    return _gcd(a, b)
qwerty_url
  • 535
  • 4
  • 12
  • 3
    Chained `is` works the same as chained `==` except it performs is-checking instead of equals-checking. If you know the difference between `is` and `==`, then what more do you need? – khelwood Jun 28 '21 at 22:04
  • 2
    Yeah IMO this would be simpler/clearer/more readable with an `and` like `if type(a) is int and type(b) is int:` – DisappointedByUnaccountableMod Jun 28 '21 at 22:06

0 Answers0