Files
30-seconds-of-code/snippets/byte_size.md
Rohit Tanwar 55f39b14bd new snippets
2018-02-01 13:49:59 +05:30

15 lines
253 B
Markdown

### byte_size
Returns the length of a string in bytes.
`utf-8` encodes a given string and find its length.
```python
def byte_size(string):
return(len(string.encode('utf-8')))
```
```python
byte_size('😀') # 4
byte_size('Hello World') # 11
```