Files
30-seconds-of-code/snippets/byte_size.md
Angelos Chalaris a340ba4492 Update some snippets
2019-08-20 10:13:54 +03:00

19 lines
304 B
Markdown

---
title: byte_size
tags: string, beginner
---
Returns the length of a string in bytes.
Use `string.encode('utf-8')` to encode the given string and return its length.
```py
def byte_size(string):
return len(string.encode('utf-8'))
```
```py
byte_size('😀') # 4
byte_size('Hello World') # 11
```