data types

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Moritz B
    New Member
    • Aug 2006
    • 6

    data types

    I was wondering if there is a way of finding out what kind of data type a variable in python is storing?

    Something like:
    > print datatype(x)
    perhaps?

    Which should return string, integer, float or list etc.

    ~ Mo
  • Moritz B
    New Member
    • Aug 2006
    • 6

    #2
    hehe ok I just found out how to do it, while randomly trying out stuff.
    >type(x) returns the data type of x

    so:
    > fg=[2,5,3,"hello"]
    > print type(fg)
    would give you:
    > <type 'list'>

    ~ Mo

    Comment

    • Reticulatus
      New Member
      • Aug 2006
      • 4

      #3
      You were pretty close:

      >>> x = "Hello"
      >>> type(x)
      <type 'str'>

      Best Regards,

      Chris

      Comment

      • Reticulatus
        New Member
        • Aug 2006
        • 4

        #4
        Sorry! Hadn't noticed you had already found the answer!

        Best Regards,

        Chris

        Comment

        Working...