When I have a list containing different values, I tried to check the type of each value and got an unexpected output. It was the Booleans True and False which threw me off. Follows the code and the results.
trial_set = {1,2,3,4,None, True, False}
new_list = [type(x) for x in trial_set]
new_set = {type(x) for x in trial_set}
print(new_list)
print(new_set)
Strange Boolean Type Behaviour
Questions:
- Why does the datatype appear first in the output though they are the last two elements in the list?
- Why is there only one datatype in output when I have two Booleans in the list?
I understand that Bool datatype is a substring of integer datatype and return 0 or 1 and I tried to figure this out from that angle but came up empty. Please help clarify.
Thank you in advance.