Do you know what the code below outputs?
import base64
text = 'abc'
print([ch for ch in text])
print([ch for ch in text.encode()])
print([ch for ch in base64.b64encode(text.encode())])
The output looks like this:
['a', 'b', 'c']
[97, 98, 99]
[89, 87, 74, 106]
ʻEncode ()` is an encoding to utf-8 and its output can be treated as a byte string, When the byte string is rotated in a for loop to get the element, an int type numerical value is output.
Similarly, if you encode with base64, the output can be treated as a byte string, When the byte string is rotated in a for loop to get the element, an int type numerical value is output. And the amount of data has increased to 4/3 from the output in utf-8.
Recommended Posts