Encoding and decoding in Python3

Source: Internet
Author: User

#一个知识点是: There are two types of string data in Python3, str type and bytes type, sty type stores unicode data, Bytes type stores bytes data

#当我们在word上编辑文件的时候, the data is stored in memory in Unicode form before it is saved.
#当我们点击保存时, the data will be encoded by the editor (such as UTF-8, GBK) encoding bytes byte string stored on the hard disk, the advantage is to save storage space------encode
#当我们又重新打开文件时, Word also places these bytes byte-string decoding city Unicode forms in memory, and the data is presented to us in clear text---------decode


1 ImportJSON2s='Fong Fong'3 Print(Type (s))#<class ' str ' >4 Print(Repr (s))#Show Store Contents # ' Fang Fang '5 Print(Json.dumps (s))#"\U82B3\U82B3"; json.dumps converts data into a string that is known to all programming languages in a special way6 7B=s.encode ("Utf-8")8 Print(type (b))#<class ' bytes ' >9 Print(repr (b))#b ' \xe8\x8a\xb3\xe8\x8a\xb3 'Ten  OneU=b.decode ("Utf-8") A Print(Type (U))#<class ' str ' > - Print(Repr (U))#' Fang Fang ' - Print(Json.dumps (U))#"\U82B3\U82B3"

Encoding and decoding in Python3

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.