How are variables stored in python?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Muffinthief
    New Member
    • May 2007
    • 51

    #1

    How are variables stored in python?

    I'm have been a long time user of python, and have recently picked up C++, but really bothers me is that in c++ you can only store integers up to a certain number (2147483647). How are variables stored and computed in python, because there is no limit to variables in python?
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    Originally posted by Muffinthief
    I'm have been a long time user of python, and have recently picked up C++, but really bothers me is that in c++ you can only store integers up to a certain number (2147483647). How are variables stored and computed in python, because there is no limit to variables in python?
    It's magic (just kidding). High level languages like Python provide a great deal of "abstractio n", which means that we don't have to think about things like memory locations and the number of bytes used to represent a certain variable type. Low level languages like C require more brain power, more care WRT memory allocation, etc and as much as 10 times more lines of code for a given task.

    Yes; learn C. It's good for low level software like drivers. Program your apps in Python (and don't worry about how variables are stored [I could tell you, but...])!

    Comment

    • Muffinthief
      New Member
      • May 2007
      • 51

      #3
      Originally posted by bartonc
      It's magic (just kidding). High level languages like Python provide a great deal of "abstractio n", which means that we don't have to think about things like memory locations and the number of bytes used to represent a certain variable type. Low level languages like C require more brain power, more care WRT memory allocation, etc and as much as 10 times more lines of code for a given task.

      Yes; learn C. It's good for low level software like drivers. Program your apps in Python (and don't worry about how variables are stored [I could tell you, but...])!
      That answers my question perfectly! (Sarcasm)

      Comment

      • Bellum
        New Member
        • Sep 2006
        • 23

        #4
        Erm, I'm not sure, but I read somewhere that after a number gets to be a certain length in Python it uses 'Long Integers' or whatever...Let me look it up.

        Wikipedia

        Comment

        • Motoma
          Recognized Expert Specialist
          • Jan 2007
          • 3236

          #5
          Originally posted by Muffinthief
          I'm have been a long time user of python, and have recently picked up C++, but really bothers me is that in c++ you can only store integers up to a certain number (2147483647). How are variables stored and computed in python, because there is no limit to variables in python?
          While I have no idea how variables are stored internally with Python, I will pass on an assignment that I had in college that helped me understand how it could be done.

          The assignment was to design a class called LongInteger, which essentially allowed us to store an integer of any size, while preserving the basic arithmetic and boolean operators, and allowing us to write and read LongInteger values from user input.

          Comment

          • Motoma
            Recognized Expert Specialist
            • Jan 2007
            • 3236

            #6
            Originally posted by Motoma
            While I have no idea how variables are stored internally with Python, I will pass on an assignment that I had in college that helped me understand how it could be done.

            The assignment was to design a class called LongInteger, which essentially allowed us to store an integer of any size, while preserving the basic arithmetic and boolean operators, and allowing us to write and read LongInteger values from user input.
            On this same note, take a look at the article I posted yesterday in the Python Articles section. It contains an implementation for long integers which could easily be ported to C++.

            Comment

            Working...