1.str ==> bytes

>>> s = 'abc'
>>> s.encode() # 可以是s.encode('utf8')或者s.encode('ascii')
b'abc'
>>> bytes(s, encoding='utf8')
b'abc'

2.bytes ==> str
>>> b = b'abc'
>>> b.decode()
'abc'
>>> str(b, encoding = 'utf8')
'abc'

 

 

 

posted on 2013-04-24 21:08  101010  阅读(270)  评论(0编辑  收藏  举报