8 Replies - 8881 Views - Last Post: 24 May 2012 - 04:01 PM Rate Topic: -----

#1 aklo  Icon User is offline

  • D.I.C Head

Reputation: 18
  • View blog
  • Posts: 229
  • Joined: 23-January 09

Difference between python 2.7 and 3.2 for beginner

Posted 23 May 2012 - 05:42 AM

Hi guys

I would like to know the difference between python 2.7 and 3.2 for a beginner to make simple software.

Basically I need to enter a competition to get into a local university due to not having a good enough grade.
The competition does not require participants to have prior software development experience...so i'm guessing it won't be that hard right? Thus the "python 2.7 or 3.2 for beginner to make simple software/code"

I can do intermediate java programming, some c# so I think python should not give me a difficult time.

Anyways I need to download a version for learning python so I'm wondering which should I download?

Is This A Good Question/Topic? 0
  • +

Replies To: Difference between python 2.7 and 3.2 for beginner

#2 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: Difference between python 2.7 and 3.2 for beginner

Posted 23 May 2012 - 10:50 AM

Perhaps you should check this post pinned at the top of the Python forum.

Also, you should check the googles.

This post has been edited by atraub: 23 May 2012 - 11:05 AM

Was This Post Helpful? 1
  • +
  • -

#3 Tayacan  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 145
  • View blog
  • Posts: 275
  • Joined: 18-January 11

Re: Difference between python 2.7 and 3.2 for beginner

Posted 24 May 2012 - 03:54 AM

The only difference you'll encounter as a beginner is whether or not print uses parentheses:

# Python 2.x
print "Hello, World"

# Python 3.x
print("Hello, World")


Was This Post Helpful? 0
  • +
  • -

#4 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: Difference between python 2.7 and 3.2 for beginner

Posted 24 May 2012 - 08:17 AM

View PostTayacan, on 24 May 2012 - 06:54 AM, said:

The only difference you'll encounter as a beginner is whether or not print uses parentheses:


False! For example, input is also very different, and the way python 2 and python 3 handle division is different too.

This post has been edited by atraub: 24 May 2012 - 08:17 AM

Was This Post Helpful? 2
  • +
  • -

#5 Tayacan  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 145
  • View blog
  • Posts: 275
  • Joined: 18-January 11

Re: Difference between python 2.7 and 3.2 for beginner

Posted 24 May 2012 - 08:33 AM

Damn... You're right, I should have thought about input. I hadn't actually thought about division before, probably because I rarely use integer division on purpose. I guess int(a/x) will give you the same result as integer division in python 2.x would.

This post has been edited by atraub: 24 May 2012 - 08:51 AM
Reason for edit:: removed accidental smiley

Was This Post Helpful? 0
  • +
  • -

#6 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: Difference between python 2.7 and 3.2 for beginner

Posted 24 May 2012 - 08:55 AM

just use // for integer division and / for true division in Python3

There are some other things to keep in mind, for example:

In 2.x, this is a very memory intesive operation
for i in range(20000000)


because it literally creates a list of 20,000,000 elements (0 - 19,999,999) and iterates over it.. that's a lot to hold in memory. However, the same operation in 3.x isn't as bad because, while you are still iterating 20,000,000 times, a list isn't actually generated, instead a number generator is. This default behavior was a significant improvement (although 2.x has xrange which behaved in this way).

I found this example at python.org
import time

#use time.time() on Linux

start = time.clock()
for x in range(25000000):
    pass
stop = time.clock()

print stop - start

start = time.clock()
for x in xrange(25000000):
    pass
stop = time.clock()

print stop-start


My results:
range : 2.19573732554
xrange: 1.47376224951


This post has been edited by atraub: 24 May 2012 - 09:21 AM

Was This Post Helpful? 0
  • +
  • -

#7 Tayacan  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 145
  • View blog
  • Posts: 275
  • Joined: 18-January 11

Re: Difference between python 2.7 and 3.2 for beginner

Posted 24 May 2012 - 10:09 AM

Huh... And I didn't know about //... I must have been living under a rock :P

I actually knew about the range thing, but it didn't really come to mind as something a beginner would care about.
Was This Post Helpful? 0
  • +
  • -

#8 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: Difference between python 2.7 and 3.2 for beginner

Posted 24 May 2012 - 03:51 PM

Fair enough, but it's still good to know :)
Was This Post Helpful? 0
  • +
  • -

#9 aklo  Icon User is offline

  • D.I.C Head

Reputation: 18
  • View blog
  • Posts: 229
  • Joined: 23-January 09

Re: Difference between python 2.7 and 3.2 for beginner

Posted 24 May 2012 - 04:01 PM

Thx guys will keep those in mind!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1