美文网首页
python2 string

python2 string

作者: loinliao | 来源:发表于2018-08-07 20:07 被阅读0次

    python2 string

    1. string object and unicode object
      s = 'abc' # s is a string object
      s = u'abc' # s is a unicode object

    2. encode method
      It's a little more complex in Python 2 (compared to Python 3), since it conflates the concepts of 'string' and 'bytestring' quite a bit. Essentially, what you need to understand is that 'string' and 'character' are abstract concepts that can't be directly represented by a computer. A bytestring is a raw stream of bytes straight from disk (or that can be written straight from disk). encode goes from abstract to concrete (you give it preferably a unicode string, and it gives you back a byte string); decode goes the opposite way.
      The encoding is the rule that says 'a' should be represented by the byte 0x61 and 'α' by the two-byte sequence 0xc0\xb1.

    相关文章

      网友评论

          本文标题:python2 string

          本文链接:https://www.haomeiwen.com/subject/xmxzvftx.html