2018年10月22日月曜日

開発環境

入門 Python 3 (Bill Lubanovic (著)、斎藤 康毅 (監修)、長尾 高弘 (翻訳)、オライリージャパン)の7章(プロのようにデータを操る)、7.3(復習問題)7-1、2、3.を取り組んでみる。

コード(Emacs)

Python 3

#!/usr/bin/env python3
import unicodedata

print('1.')
mystery = '\U0001f4a9'
print(mystery)

print(unicodedata.name(mystery))

print('2.')
pop_bytes = mystery.encode('utf-8')
print(pop_bytes)

print('3.')
pop_string = pop_bytes.decode('utf-8')
print(pop_string)
print(pop_string == mystery)

入出力結果(Terminal, Jupyter(IPython))

$ ./sample1.py
1.
💩
PILE OF POO
2.
b'\xf0\x9f\x92\xa9'
3.
💩
True
$

0 コメント:

コメントを投稿