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.

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,817評(píng)論 0 10
  • 檢視閱讀的前提:主動(dòng)閱讀 對(duì)自己提4個(gè)問(wèn)題: 1、這本書(shū)的主要內(nèi)容是什么,架構(gòu)是怎樣的? 2、這本書(shū)的細(xì)節(jié)說(shuō)了什么...
    Jean_zz閱讀 354評(píng)論 0 2
  • 已有能,勿自私,人所能,勿輕譽(yù)。自己有才能,就應(yīng)當(dāng)做些對(duì)公眾有益的事,不可自私自利,別人有才能,不可心生嫉妒,輕易...
    紅彥1閱讀 161評(píng)論 1 0
  • 2001年剛參加完了高考的時(shí)候在阿吉拉旁邊鐵路線干活,那時(shí)候還不知道能不能上大學(xué),每天迎著霧靄上工,朝陽(yáng)里看著阿吉...
    藍(lán)色的海sunshine閱讀 286評(píng)論 0 2
  • 走出機(jī)場(chǎng),望見(jiàn)這片天空的時(shí)候,原本那顆雀躍不已的心忽然就平靜下來(lái),仿佛是被恩賜了什么東西之后,那種油然而生的感激和...
    小曲奇兒閱讀 607評(píng)論 0 1

友情鏈接更多精彩內(nèi)容