Python 2 and Python 3 have several differences, some of the notable ones include:
1. Print Function: In Python 2, “print” is treated as a statement rather than a function. You could print something like this: print “Hello, World!”. But in Python 3, “print” is a function, and you have to print something like this: print(“Hello, World!”).
1. Division Operation: In Python 2, the division of two integers returns an integer, while in Python 3, the division of two integers has a float result. For example, in Python 2, 3/2 = 1. In contrast, in Python 3, 3/2 = 1.5.
1. Unicode: Python 2 ascii strings are used by default, but in Python 3 strings are stored as Unicode by default.
1. Syntax: The syntax of Python 3 is simpler and easily understandable whereas Python 2 has more complicated syntax.
1. Range function: The range() function in Python 3 returns a range object that generates numbers on demand. In contrast, Python 2’s range() creates a list in memory right away, which is less efficient for large ranges.
1. Error Handling: In Python 3, errors can be handled by using: “except Exception as e”. This is not allowed in Python 2.
1. End of Life: Python 2 has reached its end of life in 2020, meaning it will not receive any further updates and is not recommended for use in new projects. Python 3 continues to be actively developed and updated.
1. Libraries: Many popular libraries have stopped supporting Python 2 after it reached end of life. New libraries and tools are often only available for Python 3.
1. Syntax to represent octal values: In Python 2 we represent octal number like 027. But in Python 3 we represent octal number like 0o27.
1. Input Function: In Python 2, raw_input() is used to take input from users, but in Python 3, raw_input() is renamed to input().