首页 > 代码库 > Python开发(一)
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 False
setdefault和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) 2
while循环:
>>> 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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。