Files
30-seconds-of-code/snippets/byte_size.md
Rohit Tanwar d580748a48 update byte
2018-02-14 13:37:02 +05:30

251 B

byte_size

Returns the length of a string in bytes.

utf-8 encodes a given string and find its length.

def byte_size(string):
    return(len(string.encode('utf-8')))
byte_size('😀') # 4
byte_size('Hello Wor') # 11