Difference Between Python2 and Python3
Python 3.0/Python 3000/Py3k is a new version of Python which is incompatible with Python 2.x.(Python 2.0 was released in 2000). Some major features that differ among the two are listed below !!
Print in Python: In Python2, print is a statement while in Python3 print is a function that is a conversion from no brackets to brackets!
Example :
In python2
Python
# syntax in Python2, # invalid for Python3 print "Hello GfG !!" |
In python3
Python3
# syntax for Python3 print ( "Hello GfG !!" ) |
- Integer Division: Integer division in Python2 yields integer.
Example: 3/2 will give 1 as an output!! (However, 3.0/2 or 3/2.0 will give 1.5 as the output).
Integer division in Python3 can give a float value if required as per the answer.
Example: 3/2 will give 1.5 as an output. - Compatibility: Python2 is easy to port to Python3. Backward compatibility is not possible in Python3 .
- Performance: Python3 helps while typing whereas Python2 is not traditionally a typed language. Also, Python3 is faster in runtime execution than Python2.
- Not equal to the operator:
Python2
Python
a = 1 b = 2 print (a <> b) |
Output:
True
Python3
Python3
print ( 'GfG' ! = 'GfG' ) |
Output:
False
- Exception:
In python3, “as” keyword was introduced.
Example:
In python2,
try:
except valueError :
In python3,
try:
except valueError as err:
Introduction to Python3
Python is a high-level general-purpose programming language. Python programs generally are smaller than other programming languages like Java. Programmers have to type relatively less and indentation requirements of the language make them readable all the time.
Note: For more information, refer to Python Programming Language
Learn Python 3 from beginners to advanced with our complete tutorial: Python 3 Tutorial
Contact Us