Codificare stringa in Python
Livello 260 battiture
Questo codifica una stringa in bytes usando la codifica UTF-8.
Codice Python
# Crea una normale stringa (Unicode)1text = "hello"# encode("utf-8") converte la stringa in un oggetto bytes usando UTF-8# Con lettere ASCII come queste, ogni carattere occupa un byte2encoded = text.encode("utf-8")# Stampa b'hello' (il prefisso b indica un oggetto bytes)3print(encoded)Output
b'hello'
Esercitati a digitare questo codice. I risultati non vengono registrati in classifica.
Simboli in questo codice
I simboli che digiti in questo codice Python e quante volte compaiono.
"× 4(× 2)× 2=× 2-× 1.× 1