Skip to content
This repository was archived by the owner on May 7, 2023. It is now read-only.

Latest commit

 

History

History
21 lines (17 loc) · 368 Bytes

byte-size.md

File metadata and controls

21 lines (17 loc) · 368 Bytes
title type tags cover dateModified
Byte size of string
snippet
string
river-house-lights
2020-11-02 19:27:07 +0200

Returns the length of a string in bytes.

  • Use str.encode() to encode the given string and return its length.
def byte_size(s):
  return len(s.encode('utf-8'))
byte_size('😀') # 4
byte_size('Hello World') # 11