成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

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

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

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

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

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


引號指示一個多行字符串,一般在定義類和函數頭時做解釋說明。
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的變量:使用變量時只需要賦值,不需要聲明或定義數據類型。

python內置的三種數據結構:

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起始和結束位置加括號。
元組最通常的用法是用在打印語句中。

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環境在進行初始化后的效果
  4. Python編程語言如何保存搜索引擎結果
  5. Python腳本在游戲中尋找自己的知音
責任編輯:佚名 來源: 騰訊科技
相關推薦

2010-03-17 16:36:10

Java信號量模型

2010-04-01 09:34:06

Oracle函數

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數組

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數據庫

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內存溢出

2010-05-04 14:30:45

Oracle數據

2010-07-15 14:25:06

Perl時間函數

2011-08-10 08:55:28

項目失敗
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 综合久久色| 亚洲毛片网站 | 亚洲国产精品一区二区三区 | 色吧色综合 | 国产亚洲精品久久久久动 | 亚洲免费一区二区 | 国产精品成人一区二区三区 | 久久久成人一区二区免费影院 | 亚洲一区二区日韩 | 欧美一级全黄 | 伊人春色成人 | 欧美久久久久久 | 国产一区二区电影 | 国产欧美综合在线 | 国产视频第一页 | 欧美炮房 | 日本激情视频中文字幕 | 久久精品| 亚洲精品乱码久久久久久按摩观 | 国产超碰人人爽人人做人人爱 | 午夜视频大全 | 天天综合永久 | 欧美专区在线 | 免费毛片网站 | 羞羞视频网站免费观看 | 可以看黄的视频 | 欧美日韩一区二区在线观看 | 日韩国产在线 | 国产精品久久久久久妇女 | 成人自拍视频网站 | 日韩视频精品 | 国产在线拍偷自揄拍视频 | 午夜电影网站 | 欧美日韩在线视频一区二区 | 欧美一区二区三区在线播放 | 在线视频一区二区三区 | 久久国产亚洲 | 国产精品美女久久久久久久久久久 | 欧美精品在欧美一区二区 | 亚洲毛片在线 | 亚洲情综合五月天 |