How to find byte size?

PHOTO EMBED

Mon Apr 20 2020 13:45:46 GMT+0000 (Coordinated Universal Time)

Saved by @Silent Eyes #python #python #function #bytesize #return

def byte_size(string):

  return(len(string.encode('utf-8')))

byte_size('😀’) # 4
byte_size('Hello World') # 11
content_copyCOPY

This code is used to fine the size of byte that how many characters are in string.

https://towardsdatascience.com/30-helpful-python-snippets-that-you-can-learn-in-30-seconds-or-less-69bb49204172