30 seconds of python

  Back to Home

byte_size

stringbeginner

Returns the length of a string in bytes.

Use s.encode('utf-8') to encode the given string and return its length.

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