If you query type(a)
, you get list
. You probably want to do a mapping of the elements to the corresponding types, so use map
:
def listType(a): new_string = "" numSum = 0 for value in map(type,a): if isinstance(value,int) or isinstance(value,float): numSum += value elif isinstance(value,str): new_string += value if new_string and numSum: print "String:", new_string print "Sum:", numSum print "This list is of mixed type" elif new_string: print "String:", new_string print "This list is of string type" else: print "Sum:", numSum print "This list is of integer type" listType(a)
Furthermore you should not print
the result of listType
, since it does not return
anything, and fix the indentation of the program. I hope it is correct now.