偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

簡介Python代碼兩大實際應用手冊

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

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

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

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


引號指示一個多行字符串,一般在定義類和函數(shù)頭時做解釋說明。
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ù)據(jù)類型。

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

list、tple和dict。

一、list常用的幾種方法:

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

展示list用法的簡單例子:

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和字符串一樣是不可變序列。元素間用逗號分隔,為了便于識別一般會在tuple起始和結(jié)束位置加括號。
元組最通常的用法是用在打印語句中。

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代碼有很多值得學習的地方,這里我們主要介紹Python代碼 ,包括介紹實際應用方面的介紹。

【編輯推薦】

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

2010-03-17 16:36:10

Java信號量模型

2010-04-01 09:34:06

Oracle函數(shù)

2010-03-19 15:16:11

Python代碼

2010-09-14 17:27:12

DIV CSS定位

2010-03-16 09:20:25

Python時間

2010-03-10 14:18:36

Python數(shù)組

2010-04-08 18:33:46

Oracle VARR

2011-07-01 10:42:51

IIS解析漏洞

2009-11-30 16:55:10

微軟合作Novell

2019-01-10 08:41:50

生物識別身份驗證指紋

2011-08-09 13:22:31

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

2017-09-13 15:37:53

2010-01-14 16:44:39

VB.NET Mont

2012-02-01 09:59:05

TitaniumPhoneGapiOS

2010-03-05 13:48:24

Python for

2010-03-31 17:40:15

Oracle SELE

2010-09-17 16:18:43

Java內(nèi)存溢出

2010-05-04 14:30:45

Oracle數(shù)據(jù)

2010-07-15 14:25:06

Perl時間函數(shù)

2011-08-10 08:55:28

項目失敗
點贊
收藏

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