python2 string

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.

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 12,181评论 0 10
  • 检视阅读的前提:主动阅读 对自己提4个问题: 1、这本书的主要内容是什么,架构是怎样的? 2、这本书的细节说了什么...
    Jean_zz阅读 2,629评论 0 2
  • 已有能,勿自私,人所能,勿轻誉。自己有才能,就应当做些对公众有益的事,不可自私自利,别人有才能,不可心生嫉妒,轻易...
    红彦1阅读 1,225评论 1 0
  • 2001年刚参加完了高考的时候在阿吉拉旁边铁路线干活,那时候还不知道能不能上大学,每天迎着雾霭上工,朝阳里看着阿吉...
    蓝色的海sunshine阅读 1,724评论 0 2
  • 走出机场,望见这片天空的时候,原本那颗雀跃不已的心忽然就平静下来,仿佛是被恩赐了什么东西之后,那种油然而生的感激和...
    小曲奇儿阅读 3,621评论 0 1

友情链接更多精彩内容