What is the difference between Python 2 and Python 3?

Beginner

Answer

Python 3 introduced several breaking changes from Python 2:

  • Print function: print "hello" vs print("hello")
  • Unicode strings: Default string type is Unicode in Python 3
  • Integer division: 5/2 returns 2.5 in Python 3, 2 in Python 2
  • Range function: range() returns an iterator in Python 3
  • Input function: raw_input() was renamed to input()

Python 2 reached end-of-life in 2020, so Python 3 is the current standard.