How to learn Python

Having learnt enough Swift to write a neat watch face app for Apple Watch this summer, I thought I’d turn my attention to learning some Python.

Firstly, I wanted a way to edit Python commands in a decent editor and run them. It appears that Xcode doesn’t support this out of the box, but this handy StackOverflow question gives the details on how to set it up.

Secondly, I wanted a series of challenges/tutorials to walk through the basic syntax of Python. is very good for this sort of thing and has a decent set of exercises to work through.

My first bug was very revealing about the differences between Python and strongly-typed languages like F# and C++:

N = int(raw_input().strip())
if (n > 10):
    print( "big" )
elif ( N < 0 ):
    print( "negative" )
    print( "normal" )

The Python Interpreter doesn’t give an error because of the typo “n > 10” instead of “N > 10” – it just carries on regardless!

Finally, Python Software Foundation seems like a good reference site with lots of examples.

See also the next post in this series.


Filed under Programming, Python

3 responses to “How to learn Python

  1. Chris R

    You should get “NameError: name ‘n’ is not defined”

    You’ll also get an invalid syntax error because you need a colon after the else. (Just one of those python idiosyncrasies).

    • Thanks Chris – agreed about both points. I’ve found that I get the “name ‘n’ is not defined” error running Python locally on my machine, but not in the online interpreter on (it just ran and produced the wrong output).

  2. Pingback: How to Learn Python II | musingstudio

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s