The difference between IS and = =:
To know the difference between IS and = =, let us first look at the ID () method, the return value of the ID method is the memory address of the object , in short, this will give us a bunch of values can not understand
' Brother Jay ' Print (Element)
Program Run Result: 1936055642416
It turns out that this is a bunch of numbers that we really can't read
Why do you mention this? Because the next thing I'm going to say is the difference between IS and = =.
We all know that = = is used to compare the two objects are equal, but is it? is actually used to compare two objects are the same (note, here is the same), and is a deeper comparison, is the direct comparison of memory address
To improve memory utilization, Python uses a method of reusing object memory for simple int objects and simple str objects, so that Python does not allocate memory for those simple objects two times, but assigns only one
A = 2= 2print is b)
Result: True
Encode () and decode ():
From the literal point of view, encode and decode are encoded and decoded respectively. In Python, the default encoding is Unicode, which means:
decode ---------> str (Unicode)---------> str
' Text '
str2 = U.encode ('gbk') # encode U with GBK encoding to get bytes type Object
Print output result: B ' \xce\xc4\xd7\xd6 '
STR3 = U.encode ('utf-8') # encode U with utf-8 encoding to get bytes type Object
Print output result: B ' \xe6\x96\x87\xe5\xad\x97 '
u1 = Str2.decode (' GBK ') # with GBK decoding str2
Print (U1)
Output Result: Text
U2 = Str3.decode (' utf-8 ') #以utf -8 decoding STR3
Print (U2)
Output Result: Text
The difference between IS and = = and encode () and Decode ()