• Animal
  • Auto
  • Computers
  • Education
  • Finance
  • Health
  • Math
  • Mobiles
  • Programming
  • Science
  • Sports
  • Technology
  • Terms
  • Web

  • Difference Between Python 2.7 and Python 3.0

    Python 2.7 vs Python 3.0

    Python is a programming scripting language just like Perl. Recently, Python 3.0 version was released. This created a lot of buzz and people want to know more about the features and decide to whether stick to Stable Python 2.7 or move / upgrade to Python 3.0.

    This post will discuss about the various Differences Between Python 2 and Python 3 and will help programmer to decide as to which one he/she should use it.

    Differences Between Python 2.7 and Python 3.0

    Introduction – Python Releases

    • Python 2.7.2 – last stable python 2 release
    • Python 3 has already seen over four years of stable releases including version 3.3 in 2012
    • “Python 3000” or “Py3K”, is the first ever intentionally backwards incompatible Python release

    Most Important differences Python 2.7 v Python 3.0

    • Most drastic improvement is the better Unicode support (with all text strings being Unicode by default)
    • Print and exec were statements – now functions (end, file, sep)
    • Integer division performs float division. Need to use floor to perform integer division
    • All classes are now new-style
    • 3.x range() returns a memory efficient iterable, not a list as in 2.x

    Python 2.7 vs Python 3.0 Key Differences

    • dict methods dict.keys(), dict.items() and dict.values() return “views” instead of lists
    • map(), filter() and zip() return iterators
    • The ordering comparison operators (<, <=, >=, >) raise a TypeError exception when the operands don’t have a meaningful natural ordering.
    • Thus, expressions like 1 < '', 0 > None are no longer valid, and e.g. None < None raises TypeError instead of returning False
    • Long integer no longer separate integer type
    • All integers are long by default
    • raw_input has been changed to input
    • Nonlocal separate variable declaration to search within enclosing function blocks
    • True, False, and None are reserved words. bool is separate type
    • BaseException is the base exception class having subclasses like Exception, SystemExit, KeyboardInterrupt
    • Relative import syntax – from .[module] import name
    • Sets can be created with {1, 2} syntax rather than set(1, 2)

    Python Old Style vs New Style classes

    If you can do exactly what you want with Python 3.x, great!

    Which version to use ?

    There are a few minor downsides, such as slightly worse library support and the fact that most current Linux distributions and Macs are still using 2.x as default

    As a language Python 3.x is definitely ready.

    When to use Python 2.x

    • If you’re deploying to an environment you don’t control, that may impose a specific version, rather than allowing you a free selection from the available versions
    • If you want to use a specific third party package or utility that doesn’t yet have a released version that is compatible with Python 3, and porting that package is a non-trivial task, you may choose to use Python 2 in order to retain access to that package
    • Twisted (for networking and other applications), gevent (a network library like Twisted, but using micro-threads rather than an explicitly asynchronous style).

    I hope now you will be able to make your wise decision on whether to pick Python 2.7 or Python 3.0

    Posted under: Programming
    1957 readers are already subscribed to this blog! Why don't you be one of them? Subscribe to this blog via your favorite RSS feed reader or by entering your email address on the form below:

    Leave a Reply

    page counter
    NiharsWorld on Twitter NiharsWorld on Facebook NiharsWorld RSS Feed