Diff between Python 2 and 3

A forum for general discussion of the Python programming language.

Diff between Python 2 and 3

Postby XndrK » Thu Mar 27, 2014 8:49 pm

Are there any important differences between Python 2 and 3, besides the print function and a revision of the division operator?

Thanks.
Proverbs 26:14 describes me a bit too well.

Version: Python 2.7.5

https://github.com/4of92000
https://github.com/PythonForum/
User avatar
XndrK
 
Posts: 172
Joined: Sat Jun 15, 2013 7:57 pm

Re: Diff between Python 2 and 3

Postby stranac » Thu Mar 27, 2014 9:31 pm

There were quite a few changes in python 3.
A few things I can think of:
  • strings are unicode by default
  • changes to the stdlib: stuff was moved around, new stuff was added
  • a lot of stuff is lazy(map, filter, zip, dict.keys, dict.values...)
  • keyword-only arguments
  • yield from
  • unpacking fanciness:
    Code: Select all
    >>> first, *rest = range(5)
    >>> first
    0
    >>> rest
    [1, 2, 3, 4]
That's just some things I can think of...
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1144
Joined: Thu Feb 07, 2013 3:42 pm

Re: Diff between Python 2 and 3

Postby metulburr » Thu Mar 27, 2014 10:32 pm

When i first started i made a quick cheat sheet
https://github.com/metulburr/random/blo ... rences.txt

Also you can use the porting guide
http://docs.pythonsprints.com/python3_p ... rting.html
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1471
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: Diff between Python 2 and 3

Postby XndrK » Mon Mar 31, 2014 4:25 pm

stranac wrote:...a lot of stuff is lazy(map, filter, zip, dict.keys, dict.values...)...


What does that mean?
Proverbs 26:14 describes me a bit too well.

Version: Python 2.7.5

https://github.com/4of92000
https://github.com/PythonForum/
User avatar
XndrK
 
Posts: 172
Joined: Sat Jun 15, 2013 7:57 pm

Re: Diff between Python 2 and 3

Postby Mekire » Mon Mar 31, 2014 5:06 pm

Lazy means things don't generate values until they are called for.
In python 2 the lazy/non-lazy distinction is easiest to see with xrange/range.
range instantly creates a list of all values; xrange only supplies one value at a time. The latter is much more memory economical for obvious reasons.

-Mek
User avatar
Mekire
 
Posts: 988
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan


Return to General Discussions

Who is online

Users browsing this forum: No registered users and 2 guests