- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are the key differences between Python 2.7.x and Python 3.x?
Python 3.0 was released in Dec. 2008. It was designed to rectify certain flaws in earlier version. The guiding principle of Python 3 was: "reduce feature duplication by removing old ways of doing things". Python 3.0 doesn’t provide backward compatibility. That means a Python program written using version 2.x syntax doesn’t execute under python 3.x interpreter. Ver 2.7 is the final major release in Python 2.x series.
Although there are quite a few differences in usages of these two versions, the most obvious ones are mentioned below −
print is a keyword in Python 2.7 but has been included as built-in function in Python 3.x. As a result parentheses are mandatory while using it in Python 3 code
print “Hello World” # is acceptable in Python 2 but not in Python 3 print (“Hello World”) #acceptable in Python 2 and Python 3
raw_input() − function from Python 2.7 has been deprecated. The input() function treats the received data as string only.
Integer division − functionality has been changed in Python 3. In Python 2.x, 5/2 results in 2, but in Python 3.x, 5/2 is 2.5
UNICODE − In Python 3.x a string is Unicode by default. In Python 2.x, string has to be explicitly defined as Unicode by prefixing it with ‘u’ ( e.g. u’hello’)
Long integer − In Python 3.x, integer objects are long by default. In Python 2.x, an integer has to be postfixed by L (e.g. 100L)
- Related Articles
- What are the differences in between python 2.x and python 3.x versions?
- Differences between Python 2.x and Python 3.x?
- Important differences between Python 2.x and Python 3.x with examples
- What are the differences between Python and an Anaconda?
- What are the differences between json and simplejson Python modules?
- What are the best Python 2.7 modules for data mining?
- Differences between MRI and X-Ray
- What are the differences and similarities between tuples and lists in Python?
- What are the differences between readline() and readlines() in Selenium with python?
- What are the differences between xpath and css in Selenium with python?
- What are the differences between thunderbolt 2 and thunderbolt 3?
- What are the differences between list, sequence and slice data types in Python?
- What are the differences between implicit and explicit waits in Selenium with python?
- What are the differences between close() and quit() methods in Selenium with python?
- What are the differences between switch_to_default_content() and switch_to.parent_frame() methods in Selenium with python?
