Skip to content

Learning Python

June 22, 2011

I recently started learning Python again, as I’ve had interest in it in the past, but stopped for some reason I don’t really remember.

I don’t follow a single source, I make use of videos, books, and random googling for answers.

I was following the MIT course I mentioned in an earlier post, Google’s Python class, and two books, “A Byte of Python“, and “Dive into Python“.

And here’s some of the things I learned:

Why this code doesn’t work in python

x = 11
print(x += 5)

While this does

x = 11
x += 5

The good people over at Stack Overflow answered this question, you’ll find the answer for this question here.

I also learned slicing, which works for strings, tuples and lists as far as I know.

A cool trick which can be done with slicing is quickly reversing a string :

s[ : :-1]    #assuming that s is a string.

Another feature in Python is the “in” operator, it checks data structures for a given element.

In Java, if you wanted to find an element, you had to use one of the binarySearch methods, or iterate over the elements of the collection and check manually.

The last thing I remember is copying and clearing a list.

list = [ 3, 5, 9]

another_list = l[:] #This creates a copy of the list, rather than another reference to the same list.

another_list[:] = [] #This clears all elements from the current list.

del list[:] #This also deletes all elements from a list.

I’m considering doing some exercises to familiarize myself further with the language, I’m thinking of using CodingBat or something similar.

I also read a little about Android development, and I think I’m getting the hang of it, even though I don’t really like dealing with XML files at all.


From → Python

Leave a Comment

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

%d bloggers like this: