[Go to site: main page, start]

0% found this document useful (0 votes)
5 views1 page

Python2 Vs Python3 Differences

The document outlines key differences between Python 2 and Python 3, highlighting changes in syntax and functionality. Notable distinctions include the treatment of print as a function in Python 3, the handling of integer division returning a float, and improved Unicode support. Additionally, error handling and input functions have been updated, with raw_input() being removed in Python 3.

Uploaded by

Priyansh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

Python2 Vs Python3 Differences

The document outlines key differences between Python 2 and Python 3, highlighting changes in syntax and functionality. Notable distinctions include the treatment of print as a function in Python 3, the handling of integer division returning a float, and improved Unicode support. Additionally, error handling and input functions have been updated, with raw_input() being removed in Python 3.

Uploaded by

Priyansh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Differences Between Python 2 and Python 3

Feature Python 2 Python 3

Print Statement print is treated as print() is a function.


a statement. Example: print("Hello")
Example: print
"Hello"

Integer Division Dividing two integers Dividing two integers returns a


returns an integer float.
(floored). Example: 5 / 2 = 2.5
Example:
5 / 2 = 2

Unicode Support Strings are ASCII by Strings are Unicode (UTF-8) by


default. Separate default. Better support for
u'' prefix needed international characters.
for Unicode.

Error Handling Uses comma syntax: Uses 'as' keyword:


except Exception, except Exception as e:
e:

Range Function range() returns a range() behaves like


list; xrange() xrange() (returns an iterator
returns an object for object). xrange() was
large loops. removed.

Input Function raw_input() reads input() always reads as a


string; input() string. raw_input() was
evaluates data. removed.

You might also like