What are the differences between Python 2 and Python 3?

1 Answers
Answered by suresh

Differences Between Python 2 and Python 3

Python 2 and Python 3 are two major versions of the Python programming language. While both versions share many similarities, there are several key differences between them:

  1. Print Statement: In Python 2, the print statement is used as print "Hello, World!", whereas in Python 3, it is used as print("Hello, World!").
  2. Integer Division: In Python 2, division of two integers returns an integer result, while in Python 3, it returns a float result.
  3. Unicode Support: Python 2 uses ASCII for strings by default, while Python 3 uses Unicode.
  4. Range Function: In Python 2, the range() function returns a list, while in Python 3, it returns a range object.
  5. Exceptions: The syntax for raising exceptions has changed slightly between Python 2 and Python 3.

It is important to be aware of these differences when working with Python code to ensure compatibility and correct behavior across both versions.

Answer for Question: What are the differences between Python 2 and Python 3?