Calculate byte size of string

import sys

def calculate_byte_size(string):
    return sys.getsizeof(string)

my_string = "Hello, world!"

byte_size = calculate_byte_size(my_string)

print("Byte size of the string:", byte_size, "bytes")

Leave a Reply

Your email address will not be published. Required fields are marked *