Python Basic small knowledge point supplement and coding

Source: Internet
Author: User

The difference between Python2 and Python3

1. Code:

Python2 default encoding is ASCII code, python3 default encoding is Utf-8

2.print:

python2.7 printing can be without parentheses, Python3 printing must be parentheses otherwise error

3.range:

Python2 is Xrange,python3 is range

4.input:

Python2 is the input in Raw_input Python3

The difference between =,== and is

= is an assignment symbol

= = is the comparison of the symbol comparison values equal

is to compare memory addresses

Small Data pool (to save memory)

Digital

Range: -5--256

x=y=print (ID (x), id (y))      x and Y memory address are the same number valid range is - 5 to 256: if the values of the two variables range from 5 to 256, then their memory addresses are the same

String

The specific range is uncertain, but there are some rules that you can refer to

1. The string cannot contain special characters

s1='Alex's2='Alexprint (S1 is    s2)------ >True s3='[email protected]'s4='[email Protected]'print (S3  is  S4)------>false

2

string A word typeface multiply, the first 20 ranges are the same memory address: S1='h'* -S2='h'* -Print (S1 isS2)--->true string A word typeface multiply, out of the 20 range is the same two memory addresses: S1='h'* +S2='h'* +Print (S1 isS2)--->false

Other data types

The list dic tuple set has no small data pool concept

Take list For example: L1=[1,]l2=[1,]print (L1  is  L2)--- >false
Coding

Ascii

No Chinese only English one byte (bytes) ==8 digit (bit)

Unicode

English: 32 bits 4 bytes

English: 32 bits 4 bytes

Utf-8

English: 8 bits 1 bytes

English: 24 bits 3 bytes

GBK

English: 8 bits 1 bytes

English: 16 bits 2 bytes

1. The binary of each encoding is not mutually recognized, it will produce garbled

2. The storage transmission of the file cannot be Unicode (only utf-8 utf-16,gbk,gb2312 ...)

Python Basic small knowledge point supplement and coding

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.