I want to check a single value inside a list and see whether its an integer or a string?
how can i check what type is in a list?
Page 1 of 11 Replies - 428 Views - Last Post: 19 April 2012 - 01:09 PM
Replies To: how can i check what type is in a list?
#2
Re: how can i check what type is in a list?
Posted 19 April 2012 - 01:09 PM
Python provides a built-in function type(object) that will return object's type, whether it be string, integer, or user-defined. If you wanted to print the type of each object in a list, I would recommend taking an approach similar to this:
for item in list:
print "%s -> %s." % (item, type(item))
This post has been edited by Brewer: 19 April 2012 - 01:12 PM
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote



|