Things i like about Python…(1)

I am just on the way back from EuroOSCON, a wonderful conference held in Amsterdam by O’Reilly this year. I sure hope they repeat this event, there were some great sessions, speakers and keynoters (with some notable exceptions, as always).

But, this is called Python, and the reason is that i decided some time ago to get into this language, and started to read the Python Tutorial on the way back in the train. Did i mention train rides are just a fantastic way of travel? You have room, you have power, and for trips like this it’s as fast as a flight, considering the time you normally waste at the airport on the way in & out.

So, first bit of nice thing. Python does not have a CHAR type, only String. I find that alone a worthy simplification. And, Python does have a slice operator, meaning i can say name = “Frank Mantek” and address it like name[0:5] to get “Frank”;. The slice has defaults, so name[:5] is the same expression, where name [6:] would give you “Mantek” by just going to the end of the string. Strings are readonly objects, so you can not do a name[0:5] = “Vanya”. And that is fine with me. Indices can be negative to indicate counting starts from the right of the string, so a name[-6:] gives you the last six characters.

Neat stuff.

This is getting continued when dealing with Lists, you can slice them as well to get sublists, which is really elegant. Lists though can be assigned to, so you could do something like:

a = [0,1,2,3,4, “Ende”]
b = [-2, -1]
a[0:0] = b
print a
-> results in [-2,-1,0, 1,2,3,4, “Ende”]

note that this is different from assigning a[0:1] = b

Technorati Tags: ,

Advertisements
Published in: on October 20, 2005 at 1:01 pm  Leave a Comment  

The URI to TrackBack this entry is: https://compressor.wordpress.com/2005/10/20/things-i-like-about-python1/trackback/

RSS feed for comments on this post.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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: