程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

The meaning of encode and decode and character array conversion in python3

編輯:Python

Python3 Medium ​encode and decode

Python3 Character encoding is often used in decode and encode function . Especially in crawling web pages , It's good to be proficient with these two functions .encode The role of , So that we can see the intuitive character into the computer byte form .decode Just the opposite , Convert the characters in byte form into what we can understand 、 Intuitive 、“ Human model ” In the form of .

str convert to bytes:

 The first way :charArray = bytes(data.encode('utf-8'))
The second way :charArray = b"test" # b" " A prefix : The following string is bytes type .
The third way :array.array('u', data)

bytes convert to str:

bytes_var.decode("utf-8").split(",")

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved