python's sixth day for me

---恢复内容开始---

#  ==  比较的是数值

a = 1000
b = 1000
print(a == b)  #True 

#  is 比较的是内存地址

>>> a = 1000
>>> b = 1000
>>> print(a ==b)
True
>>> print(a is b)
False

#  查看内存地址

>>> a = 1000
>>> b = 1000
>>> print(id(a))
2388819008784
>>> print(id(b))
2388818153424
>>>

#  小数据池 :

#  数字 :-5~256 节省空间

#  字符串 :

       1. 如果含有特殊字符(不包括下划线 ‘ _’),不存在小数据池。

       2. str(单个)* int  int > 20 不存在小数据池。

#  其他都不存在小数据池。

#  编码

    python3x 中的编码:

        python3x 中的 str 在内存中的编码方式是Unicode 。python3x 中的 str 不能直接存储和发送。

      bytes  的编码方式是非Unicode (utf-8, gbk,...)

     对于英文:

        str :       表现形式: s = 'hello,world'

           内部编码:unicode

      bytes :  表现形式:s = b'hello,world'

           内部编码: 非unicode

     对于中文:

        str:   表现形式: s = '中国'

           内部编码:Unicode

      bytes:   表现形式:s1 = b'xe4xb8xadxe5x9bxbd'

            内部编码:非Unicode

s = '中国'
s1 = s.encode('utf-8')
print(s1)       #输出为  b'xe4xb8xadxe5x9bxbd'
原文地址:https://www.cnblogs.com/stfei/p/8634122.html