check if a variable is int or string in python code example
Example 1: python check if int
colors = [11, 34.1, 98.2, 43, 45.1, 54, 54]
for x in colors:
if int(x) == x:
print(x)
#or
if isinstance(x, int):
print(x)
Example 2: how to check if a variable in python is a specific data type
isinstance(variable_name, class_name) #eg. isinstance(age, int) will return True