
Admin
Helpdice Team
What is the difference between Python 2 and Python 3 ?
<ol>
<li>Python 2 uses <strong>print</strong> as a statement and used as print "something" to print some string on the console. On the other hand, Python 3 uses <strong>print</strong> as a function and used as print("something") to print something on the console.</li>
<li>Python 2 uses the function raw_input() to accept the user's input. It returns the string representing the value, which is typed by the user. To convert it into the integer, we need to use the int() function in Python. On the other hand, Python 3 uses input() function which automatically interpreted the type of input entered by the user. However, we can cast this value to any type by using primitive functions (int(), str(), etc.).</li>
<li>In Python 2, the implicit string type is ASCII, whereas, in Python 3, the implicit string type is Unicode.</li>
<li>Python 3 doesn't contain the xrange() function of Python 2. The xrange() is the variant of range() function which returns a xrange object that works similar to Java iterator. The range() returns a list for example the function range(0,3) contains 0, 1, 2.</li>
<li>There is also a small change made in Exception handling in Python 3. It defines a keyword <strong>as</strong> which is necessary to be used. We will discuss it in Exception handling section of Python programming tutorial.</li>
</ol>
Related QNA's
- Explain Raspberry Pi ?...1 day ago