成人免费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

生物識別身份驗證指紋

2017-09-13 15:37:53

2011-08-09 13:22:31

iPhoneSqlite數據庫

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技術棧公眾號

主站蜘蛛池模板: 国产激情精品一区二区三区 | 亚洲免费在线观看 | 日本黄色免费片 | 欧美中文字幕在线观看 | 天天躁日日躁狠狠的躁天龙影院 | 福利视频一区二区三区 | 99re热精品视频 | 毛片一区二区三区 | 色综合视频 | 国产精品亚洲视频 | av在线播放免费 | 国产精品18hdxxxⅹ在线 | 国产黄a一级 | 日韩av中文 | 毛片久久久 | 成人亚洲片 | 亚洲视频在线观看免费 | 超碰在线97国产 | 天天躁日日躁狠狠躁白人 | av中文字幕在线观看 | 欧美日韩一区二区电影 | 欧美专区在线 | 国产专区在线 | 国产成人精品一区 | 国产精品国产a级 | 国产精品视频一二三区 | 中文字幕亚洲视频 | 激情欧美日韩一区二区 | 91人人视频在线观看 | 高清av电影| 精品久久久精品 | 三级av在线| 成年人在线观看视频 | 日韩中文字幕在线不卡 | 国产精品成人一区 | av黄色片| 国产一区二区自拍 | 欧美性久久| 爱爱免费视频网站 | 欧美日韩福利视频 | 亚洲性视频 |