![]() ![]() If you want to represent such a sequence as a string, it's possible to encode it into a sequence of bytes that are all inside the ASCII encoding space, but of course, at the cost of using more bytes. See for example secrets.token_bytes from the stdlib. This is because you want to work with as large as possible an output space when generating pseudo-random numbers and sequences. One example of when you might need to use bytes, is when working with crypto and pseudo-random sequence generation, where you will often end up with a sequence of bytes that cannot be represented 1-to-1 as a string. So anytime you have a sequence of bytes that is not representable as a string, you have to use bytes() or bytearray. ![]() With UTF-8 it gets a little more complicated, but you end up in a similar problem, that not all byte sequences are representable as a string. In the ASCII character encoding, there are only 128 different values, with only a subset of those being printable. For all modern computer architectures, a byte consists of 8 bits and thus can encode 256 distinct values. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |