Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

ความหมายของ Prefix 'b' หน้า String Literal ใน Python

Python 2: prefix 'b' หรือ 'B' ถูก ignore

Python 3: Bytes literals ต้องมี prefix 'b' หรือ 'B' สร้าง instance ของ bytes type แทน str

  • ประกอบด้วย ASCII characters เท่านั้น
  • ค่าตัวเลข 128 ขึ้นไปต้อง escape

ความแตกต่างชัดเจนใน Python 3

str = '...'   # Unicode characters (UTF-16/UTF-32)
bytes = b'...' # sequence of octets (integers 0-255)