Important differences between Python 2.x and Python 3.x

Important differences between Python 2.x and Python 3.x  Division administrator 

print work



Blunder Handling

_future_ module

Division administrator

In the event that we are porting our code or executing python 3.x code in python 2.x, it tends to be hazardous if number division changes go unnoticed (since it doesn’t raise any mistake). It is wanted to utilize the gliding esteem (like 7.0/5 or 7/5.0) to get the normal outcome while porting our code.

print work

This is the most notable change. In this, the print catchphrase in Python 2.x is supplanted by the print() work in Python 3.x. Be that as it may, enclosures work in Python 2 if space is included after print watchword in light of the fact that the mediator assesses it as an articulation.


In Python 2, the verifiable str type is ASCII. In any case, in Python 3.x understood str type is Unicode.xrange:

xrange() territory restores a rundown for example range(3) returns [0, 1, 2] while range restores a range object I. e., range(3) returns iterator object which works like Java iterator and creates number when required.

In the event that we have to emphasize over a similar grouping on different occasions, we favor extending () as range gives a static rundown. xrange() recreates the arrangement inevitably. xrange() doesn’t bolster cuts and other rundown strategies. The benefit of xrange() is, it spares memory when the assignment is to repeat over an enormous range.

  1. In Python 3.x, the range of work presently does what xrange does in Python 2.x, so to keep our code compact, we should adhere to utilizing the range. So Python 3.x’s territory work is xrange from Python

2.x.__future__ module:

This is fundamentally not a contrast between the two forms, however a valuable thing to specify here. The possibility of the __future__ module is to help move to Python 3.x.

On the off chance that we are wanting to have Python 3.x help in our 2.x code, we can utilize _future_ imports in our code.

Important differences between Python 2.x and Python 3.x
Python programming language concept. Woman developer with her hand holding a modern sign with word python, on wire background.

Please Subscribe to my YouTube Channel


Spread the love


Leave a Reply

Your email address will not be published. Required fields are marked *