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

成都創(chuàng)新互聯(lián)堅持“要么做到,要么別承諾”的工作理念,服務領域包括:成都網(wǎng)站設計、成都網(wǎng)站建設、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣等服務,滿足客戶于互聯(lián)網(wǎng)時代的棗陽網(wǎng)站設計、移動媒體設計的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡建設合作伙伴!
字符串——單引號和雙引號的作用相同(與perl不同)
- perl -p -i -e 's/old/new/g' filename
引號指示一個多行字符串,一般在定義類和函數(shù)頭時做解釋說明。
Python代碼
- #!/usr/bin/python
- #Filename:mymodule.py
- class myModule:
- """show
- this is only one simple example"""
- pass
- p = myModule()
- print p
- #!/usr/bin/python
- #Filename:mymodule.py
- class myModule:
- """show
- this is only one simple example"""
- pass
- p = myModule()
- print p
python的變量:使用變量時只需要賦值,不需要聲明或定義數(shù)據(jù)類型。
python內(nèi)置的三種數(shù)據(jù)結(jié)構(gòu):
list、tple和dict。
一、list常用的幾種方法:
- append,count,extend,index,insert,pop,remove,reverse,sort
展示list用法的簡單例子:
Python代碼
- #!/usr/bin/python
- #Filename:using_list.py
- shoplist =['apple','mango','carrot','banana']
- print 'I have',len(shoplist),'items to purchase.'
- print 'These items are:'
- for item in shoplist:
- print item,
- print '\nI also have to buy rice.'
- shoplist.append('rice')
- print 'My shopping list is now',shoplist
- print 'I will sort my list now'
- shoplist.sort()
- print 'Sorted shopping list is ',shoplist
- print 'The first item I will buy is ',shoplist[0]
- olditem = shoplist[0]
- del shoplist[0]
- print 'I bought the',olditem
- print 'My shopping list is now',shoplist
- #!/usr/bin/python
- #Filename:using_list.py
- shoplist =['apple','mango','carrot','banana']
- print 'I have',len(shoplist),'items to purchase.'
- print 'These items are:'
- for item in shoplist:
- print item,
- print '\nI also have to buy rice.'
- shoplist.append('rice')
- print 'My shopping list is now',shoplist
- print 'I will sort my list now'
- shoplist.sort()
- print 'Sorted shopping list is ',shoplist
- print 'The first item I will buy is ',shoplist[0]
- olditem = shoplist[0]
- del shoplist[0]
- print 'I bought the',olditem
- print 'My shopping list is now',shoplist
二、tuple與list十分相似,只是tuple和字符串一樣是不可變序列。元素間用逗號分隔,為了便于識別一般會在tuple起始和結(jié)束位置加括號。
元組最通常的用法是用在打印語句中。
Python代碼
- #!/usr/bin/python
- #Filename:print_tuple.py
- age = 26
- name = 'SongYang'
- print '%s is %d years old.' %(name,age)
- print '''''%s loves that girl who he is missing.
- Why is %s playing with that python?''' % (name,name)
- #!/usr/bin/python
- #Filename:print_tuple.py
- age = 26
- name = 'SongYang'
- print '%s is %d years old.' %(name,age)
- print '''%s loves that girl who he is missing.
- Why is %s playing with that python?''' % (name,name)
Python代碼有很多值得學習的地方,這里我們主要介紹Python代碼 ,包括介紹實際應用方面的介紹。
【編輯推薦】
- Python邏輯操作中的三大應用方案
- Python字符串在實際中的操作手冊
- Python環(huán)境在進行初始化后的效果
- Python編程語言如何保存搜索引擎結(jié)果
- Python腳本在游戲中尋找自己的知音
本文名稱:簡介Python代碼兩大實際應用手冊
標題網(wǎng)址:http://www.dlmjj.cn/article/dhigssp.html


咨詢
建站咨詢
