exceptions check if is a list or dict

Solutions on MaxInterview for exceptions check if is a list or dict by the best coders in the world

showing results for - "exceptions check if is a list or dict"
David
29 May 2017
1number = 80
2pi = 3.14
3name = "pynative.com"
4complexNum = 1+2j
5
6sampleList  = ["Eric", "Scott", "Kelly"]
7studentDict = {"John":80, "Eric":70, "Donald":90}
8sampleTuple = ("Sam","Developer", 10000)
9sampleSet   = {11, 22, 33, 44, 55}
10
11flag = isinstance(number, int)
12print(number,'is an instance of int?', flag)
13
14flag = isinstance(pi, float)
15print(pi,'is an instance of float?', flag)
16
17flag = isinstance(complexNum, complex)
18print(complexNum, "is an instance of a complex number?", flag)
19
20flag = isinstance(name, str)
21print(name,'is an instance of String?', flag, "\n")
22
23flag = isinstance(sampleList, list)
24print(sampleList,'is instance of list?', flag)
25
26flag = isinstance(studentDict, dict)
27print(studentDict,'is instance of Dictionary?', flag)
28
29flag = isinstance(sampleTuple, tuple)
30print(sampleList,'is instance of Tuple?', flag)
31
32flag = isinstance(sampleSet, set)
33print(studentDict,'is instance of Set?', flag)