字符串和编码

计算机内存中:unicode

在保存与传输过程中要求encode:一般网络utf-8编码方式,对内存中的uncode字符再编码

编码:

>>> 'ABC'.encode('ascii')
b'ABC'
>>> '中文'.encode('utf-8')
b'\xe4\xb8\xad\xe6\x96\x87'

解码:

>>> b'ABC'.decode('ascii')
'ABC'
>>> b'\xe4\xb8\xad\xe6\x96\x87'.decode('utf-8')
'中文'

 len(X):如果是b"表达式"是字节码,就表示有多少个长度
:如果非字节形式,表示字符个数


格式化:
EG: 'Hello, %s' % 'world'---->'Hello, world'

 

相关文章:

  • 2021-07-12
  • 2021-10-10
  • 2021-07-02
  • 2021-12-07
  • 2022-01-18
  • 2021-05-19
  • 2021-04-19
  • 2021-12-11
猜你喜欢
  • 2021-11-17
  • 2021-06-29
  • 2021-09-20
  • 2021-06-26
  • 2022-01-28
  • 2022-12-23
  • 2021-11-13
相关资源
相似解决方案