Python‎ > ‎keywords‎ > ‎

is


Definition
The keyword compares the values and return with Boolean

Syntax
is

Parameters
N/A

a(str) is b(str)
The results are string return positive.
 >>> "Python" is "Python"
True
>>> 

list is list
The return with boolean:
 >>> [1,2,3,4] is [3,4,5]
False
>>>

operator.is_not
Testing the string through built in method operator.is_not().
 >>> len("Python Lake") is not len("Python Lake")
False

x is y
The return are as:
 >>> "Python Lake".isnumeric()
False
>>> str.isnumeric("Python Lake")
False
>>> x="Python Lake"
>>> x.isnumeric()
False
>>> x.isnumeric().__eq__(True)
False
>>> y=x.isnumeric()
>>> x is y
False


str(int()) is not int(str())
The returns are :
 >>> type("Python Research Centre".rfind("Centre"))==type(str("Python Research Centre".rfind("Centre")))
False
>>> type("Python Research Centre".rfind("Centre")) is not type(str("Python Research Centre".rfind("Centre")))
True
>>> "Python Research Centre".rfind("Centre") is not str(int("Python Research Centre".rfind("Centre")))
True
>>> "Python Research Centre".rfind("Centre").__eq__str(int("Python Research Centre".rfind("Centre")))
False
>>> "Python Research Centre".rfind("Centre") .__eq__int(str("Python Research Centre".rfind("Centre")))
True
>>>


built in 'is' methods in Decimal
The method returns with Decimal attribute test as through define function and if statement.
from decimal import Decimal

def test (a,b,c,d,e,f,g,h,i):
a=Decimal(a).is_canonical()
b=Decimal(b).is_finite()
c=Decimal(c).is_infinite()
d=Decimal(d).is_nan()
e=Decimal(e).is_normal()
f=Decimal(f).is_signed()
g=Decimal(g).is_snan()
h=Decimal(h).is_subnormal()
i=Decimal(i).is_zero()

if a==True:
print("The Decimal(",value1,")is canonical.")
else:
print("The Decimal(",value1,")is not canonical.")

if b==True:
print("The Decimal(",value2,")is finite.")
else:
print("The Decimal(",value2,")is not finite.")

if c==True:
print("The Decimal(",value3,")is infinite.")
else:
print("The Decimal(",value3,")is not infinite.")

if d==True:
print("The Decimal(",value4,")is nan.")
else:
print("The Decimal(",value4,")is not nan.")

if e==True:
print("The Decimal(",value5,")is normal.")
else:
print("The Decimal(",value5,")is not normal.")

if f==True:
print("The Decimal(",value6,")is signed.")
else:
print("The Decimal(",value6,")is not signed.")

if g==True:
print("The Decimal(",value7,")is snan.")
else:
print("The Decimal(",value7,")is not snan.")


if h==True:
print("The Decimal(",value8,")is subnormal.")
else:
print("The Decimal(",value8,")is not subnormal.")

if i==True:
print("The Decimal(",value9,")is zero.")
else:
print("The Decimal(",value9,")is not zero.")

value1=1.1
value2=-2.1
value3='infinity'
value4=0
value5=1.21
value6=10
value7=.50
value8=.12
value9=.21

test(value1,value2,value3, value4, value5,value6,value7, value8, value9)

>>> 
The Decimal( 1.1 )is canonical.
The Decimal( -2.1 )is finite.
The Decimal( infinity )is infinite.
The Decimal( 0 )is not nan.
The Decimal( 1.21 )is normal.
The Decimal( 10 )is not signed.
The Decimal( 0.5 )is not snan.
The Decimal( 0.12 )is not subnormal.
The Decimal( 0.21 )is not zero.
>>>


Comments