문자의 구성
인코딩 (방식)
unicode 타입
encode(인코딩)/decode(디코딩) 명령 사용Python 3에서는 unicode 타입이 기본
__repr__()print() 명령
In [1]:
    
c = "a"
c
    
    Out[1]:
In [2]:
    
print(c)
    
    
In [3]:
    
x = "가"
x
    
    Out[3]:
In [4]:
    
print(x)
    
    
In [5]:
    
print(x.__repr__())
    
    
In [6]:
    
x = ["가"]
print(x)
    
    
In [7]:
    
x = "가"
len(x)
    
    Out[7]:
In [14]:
    
x = "ABC"
y = "가나다"
print(len(x), len(y))
print(x[0], x[1], x[2])
print(y[0], y[1], y[2])
print(y[0], y[1], y[2], y[3])
    
    
In [9]:
    
y = u"가"
y
    
    Out[9]:
In [10]:
    
print(y)
    
    
In [17]:
    
y = u"가나다"
print(y[0], y[1], y[2])
    
    
In [26]:
    
print(type(y))
z1 = y.encode("cp949")
print(type(z1))
print(z1)
    
    
In [27]:
    
print(type(y))
z2 = y.encode("utf-8")
print(type(z2))
print(z2)
    
    
In [28]:
    
print(type(z1))
y1 = z1.decode("cp949")
print(type(y1))
print(y1)
    
    
In [29]:
    
print(type(z2))
y2 = z2.decode("utf-8")
print(type(y2))
print(y2)
    
    
In [33]:
    
"가".encode("utf-8")
    
    
In [34]:
    
unicode("가", "ascii").encode("utf-8")
    
    
In [37]:
    
u"가".decode("utf-8")
    
    
In [38]:
    
u"가".encode("ascii").decode("utf-8")
    
    
In [39]:
    
u"가".encode("utf-8"), u"가".encode("cp949"), "가"
    
    Out[39]:
In [40]:
    
import sys
print(sys.getdefaultencoding())
print(sys.stdin.encoding)
print(sys.stdout.encoding)
import locale
print(locale.getpreferredencoding())
    
    
PYTHONIOENCODING 로 지정가능#-*- coding: utf-8 -*-