[Go to site: main page, start]

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

Python2 Vs Python3 Differences

The document outlines key differences between Python 2 and Python 3, highlighting changes in features such as print statements, integer division, Unicode support, error handling, range functions, and input functions. Notably, Python 3 treats print as a function, returns floats for integer division, and has improved Unicode support. Additionally, Python 3 simplifies error handling and modifies the behavior of range and input functions.

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)
6 views1 page

Python2 Vs Python3 Differences

The document outlines key differences between Python 2 and Python 3, highlighting changes in features such as print statements, integer division, Unicode support, error handling, range functions, and input functions. Notably, Python 3 treats print as a function, returns floats for integer division, and has improved Unicode support. Additionally, Python 3 simplifies error handling and modifies the behavior of range and input functions.

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