• python:id与小数据池与编码


    一、id与小数据池

        id:查的是内存地址

    a = 100
    b = 100
    print(a == b)#比较的数值
    print(a is b)#比较的是id
    print(id(a),id(b))#id相同
    

        小数据池

    小数据:
    数字:-5 ~ 256 为了节省空间
    字符串:1.如果含有特殊字符,不存在小数据池


    其他都不存在小数据池。

    二、编码

    1.编码之间的二进制互不识别

    2.存储和传输010101,但不能是unicode的010101

    python3x中的编码

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

      bytes  他的编码方式是非unicode(utf-8,gbk,gb2012)

      对于英文

          str:表现形式:s = ‘abcd’

            内部编码:unicode

          bytes;表现形式:s = b‘abcd’

            内部编码:非unicode

      对于中文

          str:表现形式:s = ‘中国’

            内部编码:unicode

          bytes:表现形式:s = b‘xe4xb8xadxe5x9bxbd’

            内部编码:非uncoide

     三、转化

     1 #unicode 转化换成byte的utf-8
     2 s = 'aihalohuyouu'
     3 s1 = s.encode('utf-8')
     4 print(s1)#b'aihalohuyouu'
     5 
     6 q = '中国'
     7 q1 = q.encode('utf-8')
     8 print(q1)#b'xe4xb8xadxe5x9bxbd'
     9 
    10 #unicde转换成byte的gbk
    11 
    12 s= 'aihalohuyouu'
    13 s2 = s.encode('gbk')
    14 print(s2)#b'aihalohuyouu'
    15 
    16 q = '中国'
    17 q1 = q.encode('gbk')
    18 print(q1)#b'xd6xd0xb9xfa'

     decode

    将encode的数据decode回去

    
    
  • 相关阅读:
    201. Bitwise AND of Numbers Range
    200.Number of Islands
    199. Binary Tree Right Side View
    198. House Robber
    191. Number of 1 Bits
    190. Reverse Bits
    odoo pivot filed字段设置
    postgres 实现查找所有的子记录,child_of
    postgres 查询返回记录集的函数
    python GUI编程/窗口编程之easygui
  • 原文地址:https://www.cnblogs.com/jinfanfu/p/8654117.html
Copyright © 2020-2023  润新知