In [1]:
print(type('string'))
In [2]:
print(type(100))
In [3]:
print(type([0, 1, 2]))
In [4]:
print(type(type('string')))
In [5]:
print(type(str))
In [6]:
print(type('string') is str)
In [7]:
print(type('string') is int)
In [8]:
def is_str(v):
return type(v) is str
In [9]:
print(is_str('string'))
In [10]:
print(is_str(100))
In [11]:
print(is_str([0, 1, 2]))
In [12]:
def is_str_or_int(v):
return type(v) in (str, int)
In [13]:
print(is_str_or_int('string'))
In [14]:
print(is_str_or_int(100))
In [15]:
print(is_str_or_int([0, 1, 2]))
In [16]:
def type_condition(v):
if type(v) is str:
print('type is str')
elif type(v) is int:
print('type is int')
else:
print('type is not str or int')
In [17]:
type_condition('string')
In [18]:
type_condition(100)
In [19]:
type_condition([0, 1, 2])