Python 'getsizeof' Command the Real Purpose

In Python, there are many objects. Out of those List (arrays) is one type.  To get the number of elements present in a List is not easy. So how to get this? To do you need the 'getsizeof' command.

Import 'sys' Library.

You need to import the 'sys' library to use the SIZE commands. 

>>> import sys

Congrats to you since you have now imported the SYS library. The command name is "getsizeof".

Check the below example.

print("An Integer:")
i = int(100)

The result will be: 100

What is the size command?  - is to get the size of elements. It gives the result based on the object you are being used. Suppose, if you use Strings, you will get String length.

Python Command to get the Size of an Object

How to use the 'getsizeof' command?


print("Empty string:")
empty_string = ""


print("A normal string")
s = "Hello world"


print("Increasing string:")
for i in range(0,5):
empty_string = empty_string + chr(i)



Popular posts from this blog

Hyperledger Fabric: 20 Real Interview Questions

How to Fix Python Syntax Errors Quickly

7 AWS Interview Questions asked in Infosys, TCS