Python str与bytes之间的转换

    # bytes object 
    b = b"example"
    
    # str object 
    s = "example"
    
    # str to bytes 
    sb = bytes(s, encoding = "utf8")
    
    # bytes to str 
    bs = str(b, encoding = "utf8")
    
    # an alternative method 
    # str to bytes 
    sb2 = str.encode(s)
    
    # bytes to str 
    bs2 = bytes.decode(b)
posted @ 2018-11-20 22:19  暮晨  阅读(189)  评论(0编辑  收藏  举报

Aaron Swartz was and will always be a hero