isinstance(num1 and num2, int)
Is the same as
t1 = num1 and num2
if isinstance(t1, int)
The result of an and between two numbers returns the first Falsy value if there are any, else returns the last value in the expression.
Some examples:
In [24]: 1.4 and 2
Out[24]: 2
In [25]: 1.4 and 2 and 3
Out[25]: 3
In [26]: 1.4 and 0 and 2
Out[26]: 0
For more information, see Strange use of "and" / "or" operator.
If you want to test both, you have to do them separately:
def is_integer(num1, num2):
if isinstance(num1, int) and isinstance(num2, int):
return 'Yes'
return 'No'
Which is a more wieldy way of writing
def is_integer(num1, num2):
if all(isinstance(n, int) for n in (num1, num2)):
return 'Yes'
return 'No'
...with the all
function which generalises to more than 2 arguments.
Better still, have your function accept a variable number of arguments:
def is_integer(*args):
if all(isinstance(n, int) for n in args):
return 'Yes'
return 'No'
Better still, return a boolean result:
def is_integer(*args):
return all(isinstance(n, int) for n in args)