By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,199 Members | 1,064 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,199 IT Pros & Developers. It's quick & easy.

How are variables stored in python?

P: 51
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?
May 14 '07 #1
Share this Question
Share on Google+
5 Replies


bartonc
Expert 5K+
P: 6,596
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 "abstraction", 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...])!
May 15 '07 #2

P: 51
It's magic (just kidding). High level languages like Python provide a great deal of "abstraction", 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)
May 15 '07 #3

P: 23
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
May 16 '07 #4

Motoma
Expert 2.5K+
P: 3,235
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.
May 17 '07 #5

Motoma
Expert 2.5K+
P: 3,235
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++.
May 19 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.