zoukankan      html  css  js  c++  java
  • Python3笔记023

    5.2 字符串编码转换

    5.2.1 encode()方法以 encoding 指定的编码格式编码字符串

    str.encode([encoding="utf-8"][errors="strict"])
    
    str1 = "星期一星期二星期三星期四星期五星期六星期日"
    byte1 = str1.encode('UTF-8')
    print(byte1)
    output:
    b'xe6x98x9fxe6x9cx9fxe4xb8x80xe6x98x9fxe6x9cx9fxe4xbax8cxe6x98x9fxe6x9cx9fxe4xb8x89xe6x98x9fxe6x9cx9fxe5x9bx9bxe6x98x9fxe6x9cx9fxe4xbax94xe6x98x9fxe6x9cx9fxe5x85xadxe6x98x9fxe6x9cx9fxe6x97xa5'
    

    5.2.2 decode()方法以 encoding 指定的编码格式解码字符串

    bytes.decode([encoding="utf-8"][,errors="strict"])
    
    byte1 = b'xe6x98x9fxe6x9cx9fxe4xb8x80xe6x98x9fxe6x9cx9fxe4xbax8cxe6x98x9fxe6x9cx9fxe4xb8x89xe6x98x9fxe6x9cx9fxe5x9bx9bxe6x98x9fxe6x9cx9fxe4xbax94xe6x98x9fxe6x9cx9fxe5x85xadxe6x98x9fxe6x9cx9fxe6x97xa5'
    str1 = byte1.decode('GBK')
    print(str1)
    output:
    星期一星期二星期三星期四星期五星期六星期日
    
  • 相关阅读:
    SPOJ 10628 求树上的某条路径上第k小的点
    zoj 2112 动态区间求第k大
    SPOJ QTREE 树链剖分
    FZU 2082 过路费
    bzoj 1036 Tree Count
    POJ 3237
    C
    G
    E
    B. Split a Number(字符串加法)
  • 原文地址:https://www.cnblogs.com/infuture/p/13237589.html
Copyright © 2011-2022 走看看