Size of an object in Python

0 votes
I want to find the size of any object in Python. For example, if i is an object that stores the value "5", how should I find the memory space occupied by it?
May 25, 2018 in Python by Hamartia's Mask
• 1,580 points
172 views

1 answer to this question.

0 votes

Use sys.getsizeof() function:

>>> import sys
>>> s = "string object"
>>> i = 56
>>> sys.getsizeof(s)
38
>>> sys.getsizeof(i)
14
>>>

The size of the objects is given in bytes 

answered May 25, 2018 by Nietzsche's daemon
• 4,260 points

Related Questions In Python

0 votes
1 answer

How to check the memory usage of an object in python

Hi, @Roshni, You can use this code below: import ...READ MORE

answered Jun 26 in Python by Gitika
• 37,660 points
181 views
0 votes
1 answer

How can I find out the index of an element from row and column in Python?

You probably want to use np.ravel_multi_index: [code] import numpy ...READ MORE

answered Apr 16, 2018 in Python by charlie_brown
• 7,780 points
314 views
0 votes
1 answer

How can I convert a list of dictionaries from a CSV into a JSON object in Python?

You could try using the AST module. ...READ MORE

answered Apr 17, 2018 in Python by anonymous
1,920 views
0 votes
1 answer

How to get the size of a string in Python?

If you are talking about the length ...READ MORE

answered Jun 4, 2018 in Python by aryya
• 7,380 points
261 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,367 views
0 votes
0 answers
+1 vote
7 answers

Count the frequency of an item in a python list

To count the number of appearances: from collections ...READ MORE

answered Oct 18, 2018 in Python by tinitales
10,935 views
0 votes
1 answer

Sorting a list of strings in Python

Use the sort function mylist.sort() READ MORE

answered May 29, 2018 in Python by Nietzsche's daemon
• 4,260 points
111 views