Wednesday, May 6, 2009

Why do I use Python?

Python, as a really good dynamic language, is ideal for various types of tasks. Less complexity, more readability and versatility makes Python my favorite programming language. Python simply understands what I mean.

a=b=c=4

a, b, c=45, 76, 98

if a in range(1,10):

if 'a' and 'g' in 'gorilla':

These are very simple. But there is more to Python. Dumping a text file:

f=open('/Users/kamyar/numbers.txt','rt')
for i in f:
print i
f.close()

Dumping a website html:

import urllib2
f=urllib2.urlopen('http://www.yahoo.com')
for i in f:
print i
f.close()

'for' loop and iterators are very flexible in Python. they can even iterate on XML files and network resources. The other strength of this language is string/sequence manipulation:

a='abcdefg'
a[1:3] #### result: 'bc'
a[-3:-1] #### result: 'ef'
a[1:5:2] #### result: 'bd'











3 comments:

  1. Good but what is ((a[1:5:2] #### result: 'bd')) mean? I can not understand it.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. # is python language comment sign. I mean showing the result by that.

    ReplyDelete