Nest all content into snippets

This commit is contained in:
Angelos Chalaris
2023-05-07 16:07:29 +03:00
parent 2ecadbada9
commit 6a45d2ec07
1240 changed files with 0 additions and 0 deletions

View File

@ -0,0 +1,22 @@
---
title: Byte size of string
type: snippet
language: python
tags: [string]
cover: river-house-lights
dateModified: 2020-11-02T19:27:07+02:00
---
Returns the length of a string in bytes.
- Use `str.encode()` to encode the given string and return its length.
```py
def byte_size(s):
return len(s.encode('utf-8'))
```
```py
byte_size('😀') # 4
byte_size('Hello World') # 11
```