Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13981

How characters and integers are stored in Python

$
0
0

I am aware that in C, characters are 1 byte, and ints are 4 bytes. When I run this code in Python to determine the storage of characters and integers, I get unexpected values. Could anyone explain this discrepancy?

>>> sys.getsizeof(1)24>>> sys.getsizeof(10)24>>> sys.getsizeof(100)24>>> sys.getsizeof("a")38>>> sys.getsizeof("b")38>>> dump = cPickle.dumps(1)>>> sys.getsizeof(dump)41>>> >>> sys.getsizeof(chr(65))38

Viewing all articles
Browse latest Browse all 13981

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>