This is the P2PU Archive. If you want the current site, go to www.p2pu.org!

Learn Python the Hard Way

My recent threads

You haven't posted any discussions yet.

Recently updated threads

Learn Python 3 the Hard Way

Go back to: General discussion

Well, since I'm going through this tutorial with Python 3 instead of Python 2.X. I thought it will be good to share my experience on the differences to take note of as we go through the exercises. I will be updating this post from time to time. Watch this space if you are using Python 3 too.

ZM L's picture
ZM L
Mon, 2011-01-31 15:02

Reserved. Will not be posting code output (other threads are for that). It will only mention main differences to take note of when u r in exercise X. Tested to ex 35 so far.

-----------------------
Exercise 1

print "Hello" --> print("Hello")
-----------------------

Exercise 3

print "Hello", 1 + 2 --> print("Hello", 1 + 2)
In python 2.X to get a floating point calculation, you add a decimal point.
2/3 = 0 (non floating point calcuation, everything behind the decimal is removed)
2.0/3 = 0.6666666666666666

In Python 3, you don't need to

2/3 = 0.6666666666666666
6/2 = 3.0

------------------------------

Exercise 4

print "Let's talk about %s." % my_name --> print("Let's talk about %s." % my_name)

------------------------------

Exercise 7

In Python 2.X
print end1 + end2 + end3 + end4 + end5 + end6,
print end7 + end8 + end9 + end10 + end11 + end12

# Output: "Cheese Burger"

In Python 3

"""
Treat the 'end' argument as something which tells Python what the last thing to do.
By Default it is to print a newline so the next print will begin on a new line
This time we set the end to be a empty space character.
"""

print(end1 + end2 + end3 + end4 + end5 + end6, end= ' ')
print(end7 + end8 + end9 + end10 + end11 + end12)

# Output: "Cheese Burger"
---------------------------

Exercise 11

raw_input("Input Text") --> input("Input Text")

--------------------------
Exercise 46 onwards.

I may not be able to help you here, they require external packages which may not yet be avaliable for python 3. Thus you need to go back to python 2.X

Having said that, Exercise 46 is a real headache. Stuck...

Amene Katanda's picture
Amene Katanda
Thu, 2011-01-27 11:15

I notice most python programmers don't recommend Python 3. reason being most python modules are written for 2. 3 is still very poor right now.

ZM L's picture
ZM L
Thu, 2011-01-27 11:36

Yep quite true, I'm doing this more as an extra step in case people want to see the differences. I don't expect people to reply to this thread but more of a place they can see as a reference if they are interested in how the example look in Python 3.