Menu

gitpiper

byte_size python Code Snippet in 2024

stringbeginner

Last Updated: 14 May 2024

Returns the length of a string in bytes.

  • Use str.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

python snippet similar to byte_size For You in May 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️