6th Day of Python Learning

Source: Internet
Author: User

The difference between Python2 and 3

In the Python3 in the Python2

Print (' ab ') means that the content () brackets are required. print ' AB ' can be added without adding.

Only range has a range and xrange (generator)

User exchange with input user exchange with Raw_input

Second, the assignment value:

Comparison values are equal.

is: the memory address is compared.

ID: The ID of the comparison is the same.

= =: Compares two values for equality.

Li1 = [A]
Li2 = Li1
Print (ID (LI1), ID (li2))

Print (Li1 is li2)

Third, small data pool

In a small data pool, the number ranges between -5---256.

L2 = 6
L3 = 6
Print (ID (L2), ID (L3)) ID is the same

L2 = 600
L3 = 600
Print (ID (L2), ID (L3)) ID is different

In the small data pool, the string: 1. Cannot have special characters, 2.s*20 or the same address, s*21 after all is two addresses.

S1 = ' a ' * 20

S2 = ' a ' * 20

Print (S1 is S2) True

S1 = ' a ' * 21

S2 = ' a ' * 21

Print (S1 is S2) False

The use of pycharm will not be allowed, it is recommended to use the terminal. Lists, dictionaries, Ganso, collections do not have this concept.

Iv. Types of bytes

1, the binary system between each encoding, it can not recognize each other, will produce garbled.
2, file storage, transmission, cannot be Unicode (because Unicode is 32 bit too large) can only be utf-8 utf-16 gbk,gb2312,asciid, etc.

For English:

STR: representation: s = ' Alex '

Encoding method: 00000001 Unicode

Bytes: representation: s = B ' Alex '

Encoding method: 00000000 Utf-8, GBK ....

For Chinese:

STR: representation: s = ' China '

Encoding method: 00000010 Unicode

Bytes: expression form: s = B ' \xe4\xb8\xad\xe5\x9b\xbd '

Encoding method: 00000010 utf-8, GBK ....

Conversion command:

Code: Encode convert str to Bytes,unicode to Utf-8 or GBK

s = ' China '

Print (S.encode (' Utf-8 '))

Print (S.encode (' GBK '))

S2 = B ' Alex '

Print (s2)

6th Day of Python Learning

Related Article

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.