Python str and bytes type (PYTHON2/3 for str processing) __python

Source: Internet
Author: User

This article is tested under Python 3, and Python 2.x is slightly different. 1. Str/bytes

>> s = ' 123 '
>> type (s)
str

>> s = B ' 123 '
bytes
2. type conversion between STR and bytes

The conversion between Python str and bytes

The type conversion between STR and bytes is as follows: Str⇒bytes:bytes (S, encoding= ' UTF8 ') bytes⇒str:str (b, encoding= ' Utf-8 ')

In addition, the two can be converted by encoding and decoding, and STR is encoded into bytes format: str.encode (s) bytes format is encoded in str type: Bytes.decode (b) 3. Strings in Python2, Python 3 Down

What is Tensorflow.compat.as_str ()?

Python 2 handles strings as a native bytes type, not Unicode.
All strings in Python 3 are Unicode types.

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.