is
when comparing type
of two objects259 if data is None:
260 return None
261
262 if type(klass) == str:263 if klass.startswith("list["):
264 sub_kls = re.match(r"list\[(.*)\]", klass).group(1)
265 return [self.__deserialize(sub_data, sub_kls) for sub_data in data]
It is recommended to use identity test
( is
) instead of equality test ( ==
) when you need to compare types of two objects.
if type(x) == str:
print(x)
if type(x) is str:
print(x)
# Alternatively,
if isinstance(x, str):
print(x)