1 Replies - 488 Views - Last Post: 19 April 2012 - 01:09 PM Rate Topic: -----

#1 stevo93  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 09-April 12

how can i check what type is in a list?

Posted 19 April 2012 - 01:06 PM

I want to check a single value inside a list and see whether its an integer or a string?
Is This A Good Question/Topic? 0
  • +

Replies To: how can i check what type is in a list?

#2 Brewer  Icon User is offline

  • Awesome
  • member icon

Reputation: 178
  • View blog
  • Posts: 1,044
  • Joined: 14-June 10

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

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1