Files
30-seconds-of-code/snippets/byte_size.md
Isabelle Viktoria Maciohsek 199b646c32 Fix tags
2020-10-25 12:43:20 +02:00

290 B

title, tags
title tags
byte_size string,beginner

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'))
byte_size('😀') # 4
byte_size('Hello World') # 11