Python Sixth day

Source: Internet
Author: User

1. Is and = = Difference
ID () function

Small Data pool (constant pool): Store the values we have used in the? Small data pool. For other variable quantities.

Small data pools are used for numbers and strings, and other data types do not exist.

For numbers: -5~256 is added to the small data pool. Each use is the same object.

For strings:

1. If it is plain text information and underscores. Then this object will be added to the data pool

2. If it is with a special character. Then it will not be added to the small data pool. Every time it's new.

3. If the case is a single letter *n. ' A ' *20, within 20 units is possible. More than 20 units will not be added to the? Small Data pool

s = ' Alex ' Print (ID (s)) # 4326667072

s = "Alex" Print (ID (s)) # 4326667072

S1 = "@1 2"

S2 = "@1 2"

Print (ID (S1))

Print (ID (s2))

# The results are consistent, but inconsistent in the terminal. So in Python, the command-line code and the code in the py file may run differently.

Summarize:
= = Determine the values on both sides

is to determine the memory address


Review code:
1. ASCII: English, special characters, numerals, 8bit, 1byte
2. GBK: Chinese 16bit, 2byte. Compatible with ASCII
3. Unicode: Universal code, 32bit 4byte. Compatible with ASCII
4. UTF-8: variable-length Unicode. English: 8bit, Europe: 16bit, Chinese: 24bit 3byte

Python2 can only be used in ASCII
Python3 has Unicode, the default encoding is Unicode
In memory, Unicode is used. Hard drives and network transmissions are utf-8 or GBK.

2. Encode () encoding. Gets the result after the encoding. bytes
3. Decode () decoding. Bytes programming our familiar strings

Python Sixth day

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.