Python encoding

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

Python encoding
Python
Encoding judgment in Python
Base64 encoding images in Python 3
kafka python
Python basics ⑤
python + lottery 6
Built-in python
Python comprehension
Python technique
Studying python
Python 2.7 Countdown
Python memorandum
Python FlowFishMaster
Python service
python function ①
Python basics
Python memo
ufo-> python (3)
Python comprehension
install python
Python Singleton
Python basics ④
Python Memorandum 2
python memo
Python Jinja2
Python increment
python tips
Change python default encoding to utf-8
Installing Python 3.4.3.
Try python
Python memo
Python iterative
Python algorithm
[Python] Variables
Python functions
Python sys.intern ()
Python decimals
python underscore
Python summary
Start python
[Python] Sort
Note: Python
Python basics ③
Python basics
[Scraping] Python scraping
Python update (2.6-> 2.7)
Python memorandum
python learning
Hannari Python 2020
python memorandum
Download python
python memorandum
Python memo
started python
Python #JSON
python quiz
Python note
Python string
Python installation
ufo-> python (2)