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'
Good but what is ((a[1:5:2] #### result: 'bd')) mean? I can not understand it.
ReplyDeleteThis comment has been removed by the author.
ReplyDelete# is python language comment sign. I mean showing the result by that.
ReplyDelete