Python basics 6: python Basics

Source: Internet
Author: User

Python basics 6: python Basics
I. id

The value to be compared. The output result is True or False.

Is compares the memory address

 

Id to view the memory address

 

The memory address is equivalent to the room number a = 1000

B = 1000

Print (a = B)

#== Compare values

# Is compares the memory address.

# Print (a is B)

# View the memory address id ()

# Print (id ())

# Print (id (B ))

Ii. Small Data Pool

# Number:-5 ~ 256 space saving.

 

# String: 1. If it contains special characters, there is no small data pool.

#2, str (single) * int> 20 does not have a small data pool.

 

# No other small data pool exists.

Iii. Encoding

The storage and transmission speed is 0101, But Unicode encoding cannot be used for transmission.

Encoding in python3: In python3, str is encoded in Unicode in memory. Str in python3 cannot be directly stored and sent.

Bytes encoding is not Unicode (UTF-8, GBK, gb2312 ....)

For English: str format: s = 'kuoiea'
Internal encoding: Unicode
Byte representation s = B 'kuoiea'
The internal encoding format is non-unicode.

For Chinese: str format: s = 'China'
Internal encoding: Unicode
Byte representation s = B '\ xe4 \ xb8 \ xad \ xe5 \ x9b \ xbd'
The internal encoding format is non-unicode.


Encode encoding: converts the str type to the byte type.
Decode decoding: Convert byte type to str type

# S = 'fdsagsadfsad open carrefour; fdsafdsa on time '# IP address and port etc. # s1 = input (' ') # s1 # s = 'laonanhai' # s1 = B 'laonanhai' # print (type (s) # print (type (s1 )) # s = 'Alex '# str # s1 = s. encode ('utf-8') # bytes # encode encoding: str ---> bytes # s = 'Hello girl '# s1 = s. encode ('utf-8') # print (s1) # s = 'Hello girl '# s1 = s. encode ('gbk') # print (s1) # s = 'China' # s1 = s. encode ('utf-8') # print (s1) # s = 'China' # s1 = s. encode ('gbk') # print (s1)

 

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.