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)