Skip to content

Home

Byte size of string

Returns the length of a string in bytes.

def byte_size(s):
  return len(s.encode('utf-8'))

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

More like this

Start typing a keyphrase to see matching snippets.