zoukankan      html  css  js  c++  java
  • 323 id与小数据池

    a = 1000
    b = 1000
    print(a == b)
    == 比较的是数值
    is 比较的是内存地址。
    print(a is b)
    查看内存地址id()
    print(id(a))
    print(id(b))

    小数据池:

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

    字符串: 1,如果含有特殊字符,不存在小数据池。
    2,str(单个) * int int > 20 不存在小数据池。

    其他都不存在小数据池。

    1,编码之间的二进制互不识别。
    2,存储和传输010101,但是不能是unicode的0101010.

    数据类型:
    int
    bool

    str
    byte 与str的方法相同

    list
    dict

    python3x 中的编码:
    python3x 中 str 在内存中的编码方式是unicode。python3x 中的str不能直接存储,和发送。
    bytes 他的编码方式是非unicode(utf-8,gbk,gb2012.....)。

    对于英文:
    str: 表现形式:s = 'laonanhai'
    内部编码:unicode
    bytes:
    表现形式:s = b'laonanhai'
    内部编码:非unicode.
    对于中文:
    str: 表现形式: s = '中国'
    内部编码:unicode
    bytes: 00000001
    表现形式:s1 = b'xe4xb8xadxe5x9bxbd'
    内部编码:非unicode.
    
    
    s = 'alex'  # str
    s1 = s.encode('utf-8') # bytes
    encode 编码 :str --- > bytes
    s = 'hello girl'
    s1 = s.encode('utf-8')
    print(s1)

    s = 'hello girl'
    s1 = s.encode('gbk')
    print(s1)
    s = '中国'
    s1 = s.encode('utf-8')
    print(s1)

    s = '中国'
    s1 = s.encode('gbk')
    print(s1)


  • 相关阅读:
    bestcoder #66
    uva11093 Just Finish it up
    UVA 12627 Erratic Expansion
    uva714 Copying Books
    龟兔赛跑
    神、上帝以及老天爷
    不容易系列之(3)―― LELE的RPG难题
    C. Watto and Mechanism
    Phone List hdu1671
    B. Han Solo and Lazer Gun
  • 原文地址:https://www.cnblogs.com/Mr-Murray/p/8643568.html
Copyright © 2011-2022 走看看