1x = isinstance(5, int)
2y = isinstance(6.5, int)
3print(x)
4print(y)
5
6output:
7True
8False
1sample_list = ['Emma', 'Stevan', 12, 45.6, 1 + 2j, "Eric", ]
2number_list = []
3string_list = []
4for item in sample_list:
5 if isinstance(item, (int, float, complex)):
6 number_list.append(item)
7 elif isinstance(item, str):
8 string_list.append(item)
9
10# String List
11print(string_list)
12# Output ['Emma', 'Stevan', 'Eric']
13
14# Number list
15print(number_list)
16# Output [12, 45.6, (1+2j)]
1#Python isinstance Function
2x = isinstance("Hello", (float, int, str, list, dict, tuple))