标签:python开发
python
>>> s=‘tou siheoiw‘ >>> ‘%s is number %d‘ % (s[:6],1) ‘tou si is number 1‘
>>> hi=‘‘‘hi there‘‘‘ >>> hi ‘hi\nthere‘
>>> book ={‘title‘:‘Python Web Development‘,‘year‘:2008}
>>> book
{‘year‘: 2008, ‘title‘: ‘Python Web Development‘}
>>> ‘year‘ in book
True
>>> ‘pub‘ in book
Falsesetdefault和get一样,dict.get(key)或是dict[key]
>>> d ={‘title‘:‘Python Web Development‘,‘year‘:2008}
>>> d
{‘year‘: 2008, ‘title‘: ‘Python Web Development‘}
>>> d.setdefault(‘pub‘,‘Addison Wesley‘)
‘Addison Wesley‘
>>> d
{‘year‘: 2008, ‘pub‘: ‘Addison Wesley‘, ‘title‘: ‘Python Web Development‘}
>>> del d[‘pub‘]
>>> d
{‘year‘: 2008, ‘title‘: ‘Python Web Development‘}
>>> d[‘title‘]
‘Python Web Development‘
>>> len(d)
2while循环:
>>> while i<5: ... print i ... i +=1 ... ... 0 1 2 3 4
建一个文本
#!/bin/bash #4.4.sh i=$[ $1 % 2] if test $i -eq 0 ; then echo oushu else echo jishu fi ~
>>> for line in open(‘4.sh‘): ... if ‘jishu‘ in line: ... print line ... echo jishu
>>> for line in open(‘4.sh‘): ... print line ... #!/bin/bash #4.4.sh i=$[ $1 % 2] if test $i -eq 0 ; then echo oushu else echo jishu fi
enumerate是一个能让你同时迭代和计数的内置函数
>>> data =(123,‘abc‘,3.14) >>> for i, value in enumerate(data): ... print i,value ... 0 123 1 abc 2 3.14
本文出自 “王尼美的成人之路” 博客,请务必保留此出处http://8335914.blog.51cto.com/8325914/1536538
标签:python开发
原文地址:http://8335914.blog.51cto.com/8325914/1536538