dynamic data types

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Charlie

    #1

    dynamic data types

    Hi,

    The description of Python always mentions "very high level dynamic data
    types". Now, I can't seem to find any examples of these (nothing
    described with this term anyway). Is this simply refering to built-in
    dynamic data structures such as lists and dictionaries, with a great
    deal of operators defined on? Or is there something else meant by
    "dynamic data types" in Python?

    Regards,

    Charlie

  • rbt

    #2
    Re: dynamic data types

    Charlie wrote:[color=blue]
    > Hi,
    >
    > The description of Python always mentions "very high level dynamic data
    > types". Now, I can't seem to find any examples of these (nothing
    > described with this term anyway). Is this simply refering to built-in
    > dynamic data structures such as lists and dictionaries, with a great
    > deal of operators defined on? Or is there something else meant by
    > "dynamic data types" in Python?
    >
    > Regards,
    >
    > Charlie
    >[/color]

    I've always thought of it like this... in C, we have to do something
    like this when declaring a variable:

    int x = 0;

    We had to specifically tell the language compiler that x is an integer.
    In Python, all we have to do is:

    x = 0

    The interpretor knows that x is an integer. We can also change the type
    like this:

    str(x)
    float(x)
    long(x)

    etc...

    To me, this is why Python types are called dynamic. They are easy to
    setup and easy to modify when compared to older, more static languages.

    Bye

    Comment

    • beliavsky@aol.com

      #3
      Re: dynamic data types

      rbt wrote:
      [color=blue]
      >I've always thought of it like this... in C, we have to do something
      >like this when declaring a variable:[/color]
      [color=blue]
      >int x = 0;[/color]
      [color=blue]
      >We had to specifically tell the language compiler that x is an[/color]
      integer.[color=blue]
      >In Python, all we have to do is:[/color]
      [color=blue]
      >x = 0[/color]
      [color=blue]
      >The interpretor knows that x is an integer. We can also change the[/color]
      type[color=blue]
      >like this:[/color]
      [color=blue]
      >str(x)
      >float(x)
      >long(x)[/color]

      Just to clarify, str(x) does not change x, but

      x = str(x)

      does. Probably rbt knows this. I wonder how often this feature should
      be employed. In my Python programs, most variables keep the same type
      throughout. This makes a code easier for me to understand, and this
      constraint should facilitate translation of the code to a statically
      typed language (perhaps even a variant of Python) in the future, if
      necessary.

      The ability to grow a list with "append" is a very convenient feature
      of Python. The C++ vector is similar but stores elements of the same
      type, whereas a Python list or tuple can store elements of different
      types.

      Comment

      • Peter Hansen

        #4
        Re: dynamic data types

        Charlie wrote:[color=blue]
        > The description of Python always mentions "very high level dynamic data
        > types". Now, I can't seem to find any examples of these (nothing
        > described with this term anyway). Is this simply refering to built-in
        > dynamic data structures such as lists and dictionaries, with a great
        > deal of operators defined on? Or is there something else meant by
        > "dynamic data types" in Python?[/color]

        I'd say this is "list", "dict", "set", all the similar ones,
        plus anything custom defined by the programmer... plus probably
        just about any other data type in Python, since they're all
        "high level", the "very" part is meaningless, and they're
        pretty much all more "dynamic" than most similar things in,
        say, a language that's, uh, "less dynamic". ;-)

        Really, think of it as marketing propaganda, and don't worry
        exactly what the original author of the words intended it
        to apply to.

        -Peter

        Comment

        • Paul Simmonds

          #5
          Re: dynamic data types

          I would assume that they're refering to the fact that even the basic
          data types such as int are derived from object, and hence have methods:[color=blue][color=green][color=darkred]
          >>> int.__class__._ _base__[/color][/color][/color]
          <type 'object'>

          Java, for example, has both an Integer object and a basic int data
          type. One word. Yuck.

          Paul S.

          Comment

          • Steven Bethard

            #6
            Re: dynamic data types

            Paul Simmonds wrote:[color=blue]
            > I would assume that they're refering to the fact that even the basic
            > data types such as int are derived from object, and hence have methods:
            >[color=green][color=darkred]
            >>>>int.__class __.__base__[/color][/color]
            >
            > <type 'object'>
            >
            > Java, for example, has both an Integer object and a basic int data
            > type. One word. Yuck.[/color]

            Heh heh. Yeah, I can remember that annoyance well. I believe Java
            1.5's supposed to have auto-boxing and -unboxing though, which should
            make this less of a pain...

            Steve

            Comment

            Working...