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

簡(jiǎn)介Python代碼兩大實(shí)際應(yīng)用手冊(cè)

開(kāi)發(fā) 后端
經(jīng)過(guò)長(zhǎng)時(shí)間學(xué)習(xí)Python代碼 ,于是和大家分享一下,看完本文你肯定有不少收獲,希望本文能教會(huì)你更多東西。以下是相關(guān)內(nèi)容的詳細(xì)介紹。

本人很喜歡Python代碼,在工作中也很喜歡總結(jié)關(guān)于Python代碼的經(jīng)驗(yàn)教訓(xùn),下面就這個(gè)問(wèn)題來(lái)詳細(xì)說(shuō)一般在定義類(lèi)和函數(shù)頭時(shí),Python代碼的實(shí)際應(yīng)用方面的介紹,希望大家瀏覽以下文章會(huì)有所收獲。

字符串——單引號(hào)和雙引號(hào)的作用相同(與perl不同)

  1. perl -p -i -e 's/old/new/g' filename  


引號(hào)指示一個(gè)多行字符串,一般在定義類(lèi)和函數(shù)頭時(shí)做解釋說(shuō)明。
Python代碼

  1. #!/usr/bin/python   
  2. #Filename:mymodule.py   
  3. class myModule:   
  4. """show   
  5.  
  6. this is only one simple example"""   
  7. pass   
  8.  
  9. p = myModule()   
  10. print p   
  11.  
  12. #!/usr/bin/python  
  13. #Filename:mymodule.py  
  14. class myModule:   
  15. """show   
  16.  
  17. this is only one simple example"""   
  18. pass   
  19.  
  20. p = myModule()   
  21. print p   
  22.  

python的變量:使用變量時(shí)只需要賦值,不需要聲明或定義數(shù)據(jù)類(lèi)型。

python內(nèi)置的三種數(shù)據(jù)結(jié)構(gòu):

list、tple和dict。

一、list常用的幾種方法:

  1. append,count,extend,index,insert,pop,remove,reverse,sort  

展示list用法的簡(jiǎn)單例子:

Python代碼

  1. #!/usr/bin/python   
  2. #Filename:using_list.py   
  3.  
  4. shoplist =['apple','mango','carrot','banana']   
  5.  
  6. print 'I have',len(shoplist),'items to purchase.'   
  7.  
  8. print 'These items are:'   
  9. for item in shoplist:   
  10. print item,   
  11.  
  12. print '\nI also have to buy rice.'   
  13. shoplist.append('rice')   
  14. print 'My shopping list is now',shoplist   
  15.  
  16. print 'I will sort my list now'   
  17. shoplist.sort()   
  18. print 'Sorted shopping list is ',shoplist   
  19.  
  20. print 'The first item I will buy is ',shoplist[0]   
  21. olditem = shoplist[0]   
  22. del shoplist[0]   
  23. print 'I bought the',olditem   
  24. print 'My shopping list is now',shoplist   
  25.  
  26. #!/usr/bin/python  
  27. #Filename:using_list.py  
  28.  
  29. shoplist =['apple','mango','carrot','banana']  
  30.  
  31. print 'I have',len(shoplist),'items to purchase.'  
  32.  
  33. print 'These items are:'  
  34. for item in shoplist:  
  35. print item,  
  36.  
  37. print '\nI also have to buy rice.'  
  38. shoplist.append('rice')  
  39. print 'My shopping list is now',shoplist  
  40.  
  41. print 'I will sort my list now'  
  42. shoplist.sort()  
  43. print 'Sorted shopping list is ',shoplist  
  44.  
  45. print 'The first item I will buy is ',shoplist[0]  
  46. olditem = shoplist[0]  
  47. del shoplist[0]  
  48. print 'I bought the',olditem  
  49. print 'My shopping list is now',shoplist  
  50.  

二、tuple與list十分相似,只是tuple和字符串一樣是不可變序列。元素間用逗號(hào)分隔,為了便于識(shí)別一般會(huì)在tuple起始和結(jié)束位置加括號(hào)。
元組最通常的用法是用在打印語(yǔ)句中。

Python代碼

  1. #!/usr/bin/python   
  2. #Filename:print_tuple.py   
  3.  
  4. age = 26   
  5. name = 'SongYang'   
  6.  
  7. print '%s is %d years old.' %(name,age)   
  8. print '''''%s loves that girl who he is missing.   
  9.  
  10. Why is %s playing with that python?''' % (name,name)   
  11.  
  12. #!/usr/bin/python  
  13. #Filename:print_tuple.py  
  14.  
  15. age = 26 
  16. name = 'SongYang' 
  17.  
  18. print '%s is %d years old.' %(name,age)  
  19. print '''%s loves that girl who he is missing.  
  20.  
  21. Why is %s playing with that python?''' % (name,name)   
  22.  
  23.  
  24.  

 

Python代碼有很多值得學(xué)習(xí)的地方,這里我們主要介紹Python代碼 ,包括介紹實(shí)際應(yīng)用方面的介紹。

【編輯推薦】

  1. Python邏輯操作中的三大應(yīng)用方案
  2. Python字符串在實(shí)際中的操作手冊(cè)
  3. Python環(huán)境在進(jìn)行初始化后的效果
  4. Python編程語(yǔ)言如何保存搜索引擎結(jié)果
  5. Python腳本在游戲中尋找自己的知音
責(zé)任編輯:佚名 來(lái)源: 騰訊科技
相關(guān)推薦

2010-03-17 16:36:10

Java信號(hào)量模型

2010-03-19 15:16:11

Python代碼

2010-04-01 09:34:06

Oracle函數(shù)

2010-09-14 17:27:12

DIV CSS定位

2010-03-16 09:20:25

Python時(shí)間

2010-03-10 14:18:36

Python數(shù)組

2011-08-09 13:22:31

iPhoneSqlite數(shù)據(jù)庫(kù)

2010-01-14 16:44:39

VB.NET Mont

2010-04-08 18:33:46

Oracle VARR

2009-11-30 16:55:10

微軟合作Novell

2017-09-13 15:37:53

2010-03-05 13:48:24

Python for

2011-07-01 10:42:51

IIS解析漏洞

2019-01-10 08:41:50

生物識(shí)別身份驗(yàn)證指紋

2012-02-01 09:59:05

TitaniumPhoneGapiOS

2010-03-31 17:40:15

Oracle SELE

2010-07-20 12:44:20

Perl特殊變量

2011-08-10 08:55:28

項(xiàng)目失敗

2010-07-15 14:25:06

Perl時(shí)間函數(shù)

2011-06-21 10:48:43

網(wǎng)絡(luò)布線布線電磁
點(diǎn)贊
收藏

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