1. 程式人生 > >字符編碼,時間格式轉換

字符編碼,時間格式轉換

encode codes decode 格式 unicode轉化 instr hello AI 普通

普通字符串可以用多種方式編碼成Unicode字符串,具體要看你究竟選擇了哪種編碼:
unicodestring = u"Hello world"
# 將Unicode轉化為普通Python字符串:"encode"
utf8string = unicodestring.encode("utf-8")
asciistring = unicodestring.encode("ascii")
isostring = unicodestring.encode("ISO-8859-1")
utf16string = unicodestring.encode("utf-16")
# 將普通Python字符串轉化為Unicode:"decode"

plainstring1 = unicode(utf8string, "utf-8")
plainstring2 = unicode(asciistring, "ascii")
plainstring3 = unicode(isostring, "ISO-8859-1")
plainstring4 = unicode(utf16string, "utf-16")
assert plainstring1 == plainstring2 == plainstring3 == plainstring4

字符編碼,時間格式轉換