Learn Python 2 or 3 first?

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

Learn Python 2 or 3 first?

Postby Quantum Potatoid » Thu May 03, 2012 11:46 pm UTC

Hey, would anyone have any suggestions as to whether I should learn Python 2, or Python 3? In the long run I'll probably have to learn both.
While Python 2 has all the libraries and support, I'm thinking that getting a head start on Python 3, since it's the next up would give me an advantage in the long run.
Any thoughts?
"There's nothing wrong with having voices in your head, it's when they leave you out of the conversation you have to worry"
Spoiler:
iThis Cheese is Burning Me!
User avatar
Quantum Potatoid
 
Posts: 143
Joined: Mon Aug 06, 2007 1:15 am UTC
Location: May only be known if velocity isn't. Same rules apply with taste and texture.

Re: Learn Python 2 or 3 first?

Postby Ben-oni » Fri May 04, 2012 10:16 am UTC

Can't answer that unless we know: Why Python?
Ben-oni
 
Posts: 270
Joined: Mon Sep 26, 2011 4:56 am UTC

Re: Learn Python 2 or 3 first?

Postby freeTheInfo » Fri May 04, 2012 3:06 pm UTC

Python 3 and the latest versions of Python 2 are mostly the same. Where they differ can cause quite a bit of frustration to you, however.

Ben-oni wrote:Can't answer that unless we know: Why Python?

This is somewhat true. If you need to use Python today for work or school: learn Python 2.7; you will need to support/troubleshoot many, many Python 2 programs while working for any company that uses Python. Many enviroments don't support Python 3 yet, so you'll be developing in Python 2.7 (or lower) anyways.

I would just learn Python 2. Python 3 isn't that much different, it's documentation is less mature, and when everyone does eventually switch over to Python 3 you won't be the only person with a few problems. The Python 2 to 3 tool fixes most minor stuff anyways, and leaves you with a few nasty suprises to troubleshoot, but any problem has almost certainly been solved on StackOverflow.

Gah, I was so confused the very first time I was running Python3 and
Code: Select all
print foo
didn't work. You have to use
Code: Select all
print(foo)
now.
freeTheInfo
 
Posts: 4
Joined: Fri May 04, 2012 2:26 pm UTC

Re: Learn Python 2 or 3 first?

Postby pedros » Fri May 04, 2012 3:11 pm UTC

in the later versions of python 2 you can always do something along these lines

Code: Select all
pete@pete-desktop:~/Desktop$ python
Python 2.7.2+ (default, Oct  4 2011, 20:03:08)
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from __future__ import print_function
>>> from __future__ import division
>>> print(3/2)
1.5
>>>


rather than

Code: Select all
>>> print 3/2
1
>>>
pedros
 
Posts: 3
Joined: Mon Mar 07, 2011 11:16 pm UTC

Re: Learn Python 2 or 3 first?

Postby EvanED » Fri May 04, 2012 4:14 pm UTC

I just wish there was an from __future__ import different_types_arent_ordered_dammit so you could could properly get
Code: Select all
>>> 1 < "good"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unorderable types: int() < str()

instead of
Code: Select all
>>> 1 < "bad"
True

(What can I say? I like strong types. :-) Same thing happens with something like 1 < []. I am disappointed that 1 < True continues to not produce an error even in Python 3 though.)

FWIW, I can tell you what I'm doing. For short scripts, I'm trying to use Python 3 more; I do really prefer Python 3. For longer programs, or where I'm more interested in portability, I stick with 2. So you pretty much hit the nail on the head in the first post: Python 3 is better and in a few years will be the norm, but there's a lot of inertia getting there.
EvanED
 
Posts: 3781
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI


Return to Coding

Who is online

Users browsing this forum: kerrownChoole, Sizik, toastermm and 6 guests