自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Python for in實(shí)際應(yīng)用代碼操作方法

開發(fā) 后端
Python for in的應(yīng)用是一個(gè)比較基礎(chǔ)的應(yīng)用技巧,對(duì)于Python編程人員來說是必須要掌握的技能。在這里我們將會(huì)對(duì)此做一個(gè)詳細(xì)的介紹。

Python編程語言一經(jīng)推出就憑借其簡(jiǎn)單易用這一特點(diǎn)極大的吸引了開發(fā)人員的注意。那么它的到來究竟給我們的編程方式帶來了哪些改變呢?我們今天就來從Python for in的應(yīng)用方法來體驗(yàn)這種變化。

Python for in代碼示例:

  1. #!/usr/bin/env python  
  2. 'makeTextFile.py -- create text file'  
  3. import os  
  4. ls = os.linesep  
  5. # get filename  
  6. while True:  
  7. if os.path.exists(fname):  
  8. print"*** ERROR: '%s' already exists" % fname  
  9. else:  
  10. break  
  11. # get file content (text) lines  
  12. all = []  
  13. print "\nEnter lines ('.' by itself to quit).\n"  
  14. # loop until user terminates input  
  15. while True:  
  16. entry = raw_input('> ')  
  17. if entry == '.':  
  18. break  
  19. else:  
  20. all.append(entry)  
  21. # write lines to file with proper line-ending  
  22. fobj = open(fname, 'w')  
  23. fobj.writelines(['%s%s' % (x, ls) for x in all])  
  24. fobj.close()  
  25. print 'DONE!' 

希望這里介紹的Python for in的實(shí)際應(yīng)用示例能給大家在學(xué)習(xí)中帶來些幫助。

【編輯推薦】

  1. 深入探討Python序列神奇之處
  2. Python數(shù)據(jù)轉(zhuǎn)換實(shí)現(xiàn)代碼深入分析
  3. Python增量備份實(shí)現(xiàn)技巧分享
  4. Python命名約定基本內(nèi)容解析
  5. Python編程規(guī)范具體內(nèi)容解析
責(zé)任編輯:曹凱 來源: 博客園
相關(guān)推薦

2009-12-30 15:53:28

Silverlight

2010-03-19 13:04:12

Pyhon腳本解釋器

2010-02-03 10:23:47

C++操作符重載

2010-02-01 09:40:08

Python操作

2010-01-04 16:50:04

Silverlight

2010-09-30 10:41:29

2010-01-07 10:46:27

VB.NET Sock

2010-03-04 09:58:32

安裝Python

2010-03-09 19:07:01

Python語法

2010-05-31 18:16:48

MySQL數(shù)據(jù)庫備份

2010-07-27 13:16:50

DB2使用所有內(nèi)存

2010-04-19 16:28:04

Oracle導(dǎo)出

2010-03-17 10:01:12

Python安裝

2009-12-15 13:59:42

Ruby對(duì)象操作

2010-08-06 11:21:45

IBM DB2 數(shù)據(jù)復(fù)

2010-03-04 14:32:24

Python自動(dòng)下載文

2010-03-15 15:18:23

Python運(yùn)行

2010-03-17 12:20:15

Python Libr

2010-05-31 14:59:36

PHP + MySQL

2010-03-17 16:27:39

Python矩陣轉(zhuǎn)置
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)