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.