Python Basics-06

Source: Internet
Author: User

is and the difference between = =

is to compare memory addresses

= = Comparison is a value

ID (variable) returns the memory address of this variable to you

Example: s= "Jay Chou"

S1=s

Print (ID (s), ID (S1))

Special: lst1=[1,4,7]

lst2=[1,4,7]

Lst1.append ("small white")

Print (LST1,LST2)

Print (ID (lst1), ID (lst2)) #内存地址不同

Small Data Pool (Chang): Store the values we have used in a small data pool. For other variables to use.

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 small 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 are not added to a small data pool.

Note (in general): in the py file. If you simply define a string. Then normally it would be

is added to the small data pool. We can think of this: when using strings, Python will help us put the string

Cache and point directly to the string the next time you use it. Can save a lot of memory.

Coding

ASCII 8bit 1byte English lowercase capital letters, special characters, numbers

GBK 16bit 2byte Chinese compatible ASCII

UNICODE 32bit 4byte Universal footprint

UTF-8 Unicode upgrade English 1byte Chinese 3byte

1. The ASCII code is used by default in Python2. Therefore, Chinese is not supported. If you need to change the encoding in Python2, you need to write at the beginning of the file: #-*-Encoding:utf-8-*-

2. Python3: Unicode code is used in memory

Use UTF-8 or GBK during transmission.

In memory, the encoding is Unicode while the program is running.

In a program, a string can be encoded into a bytes type of data.

Code encode

The result after encoding is actually the same as the original result, just look different.

Python Basics-06

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.