what is the difference between 2.x and 3.x Python


In this post, I am writing about the difference between python 2.X and 3.X and I will try to keep it short and informative.

String Handling

In Python 3, text strings are Unicode by default. In Python 2, strings are stored as ASCII by default–you have to add a “u” if you want to store strings as Unicode in Python 2.x.


Python 3  integer division

Python 2.x rounds your calculation down to the nearest whole number
Python 3, the division expression will return the expected result of without having to worry about adding those extra zeroes.

Print statement 

In Python 3, the print statement in Python 2 is replaced by print() function
Python 2 --> print “hello world!”
Python 3 --> print (“hello world!”)


Python 2 range() vs xrange() and Python 3 range()


In Python 2, range() returns list and xrange() memory efficient iterable and in python 3 xrange() functionality implemented in range(). There is no xrange in python 3

You Might Also Like

1 comments

  1. Very Informative and creative contents. This concept is a good way to enhance knowledge. Thanks for sharing. Continue to share your knowledge through articles like these.

    Data Engineering Services 

    Data Analytics Solutions

    Artificial Intelligence Solutions

    Data Modernization Solutions

    ReplyDelete