new snippets

This commit is contained in:
Rohit Tanwar
2018-02-01 13:49:59 +05:30
parent b5a1fa18ba
commit 55f39b14bd
27 changed files with 292 additions and 34 deletions

15
snippets/byte_size.md Normal file
View File

@ -0,0 +1,15 @@
### 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
```