Commit ee9734
2026-08-03 23:19:16 Niklas Polke: Create Bytes Bytearray| /dev/null .. python/bytes.md | |
| @@ 0,0 1,23 @@ | |
| + | # Bytes Bytearray |
| + | bytes/bytearray can contain numbers between 0 and 255 |
| + | |
| + | ## Overview |
| + | | What | How | |
| + | | - | - | |
| + | | `bytes` | immutable byte sequence | |
| + | | `bytes(10)` | create bytes of length 10 | |
| + | | `bytes[0]` | get first byte | |
| + | | - | - | |
| + | | `bytearray` | mutable byte sequence | |
| + | | `bytearray(10)` | create bytearray of length 10 | |
| + | | `bytearray[0]` | get first byte | |
| + | | - | - | |
| + | | *bytes from bytearray* | `bytes(bytearray)` | |
| + | | *bytearray from bytes* | `bytearray(bytes)` | |
| + | | *copy from bytearrayOrBytes* | `bytearray(bytearrayOrBytes)` | |
| + | |
| + | handle both with one method: |
| + | ```python |
| + | def method(data: bytearray | bytes): # accept both types |
| + | mydata = bytearray(data) # copy of bytes or bytearray |
| + | ``` |
