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

ความแตกต่างหลักระหว่าง Python 2.7.x และ Python 3.x

Python 3.0 ปล่อย Dec 2008 แก้ไขข้อบกพร่องรุ่นเก่า หลักการ: "ลด feature duplication โดยลบวิธีเก่า" ไม่ backward compatible โค้ด 2.x รันบน 3.x ไม่ได้ 2.7 เป็น major release สุดท้ายของ 2.x

ความแตกต่างเด่น:

  • print - keyword ใน 2.7, built-in function ใน 3.x (ต้องมีวงเล็บ)
  • raw_input() - deprecated ใน 3.x ใช้ input() แทน (คืน string เสมอ)
  • Integer division - 2.x: 5/2 = 2 | 3.x: 5/2 = 2.5
  • Unicode - 3.x: string เป็น Unicode default | 2.x: ต้อง prefix u'hello'
  • Long integer - 3.x: int เป็น long default | 2.x: ต้อง suffix L (เช่น 100L)