python筆記1
一、幫助系統:help(command|module) eg. help(list)
二、python基礎
python資料結構:
列表
list=['itemA','itemB','itemC']
元組
array=('itemA','itemB',list)
字典
dict={
'itemA':'valueA',
'itemB':'valueB',
'itemC':'valueC'
}
list的使用:
---------------------------------------------------
arraylist = ['panda','dog','cat','monkey','mouse']
print "the array's length is",len(arraylist)
print "n"
print "the first item is ",arraylist[0]
arraylist.append('snake')
print "nafter add an item 'snake',the array become",
for item in arraylist:
print item
arraylist.sort()
print "nafter sort the array become",
for item in arraylist:
print item,
del arraylist[0]
print "nafter del the first item the array become",arraylist
---------------------------------------------------
元組的使用:
---------------------------------------------------
zoo=('monkey','mouse','tiger','cat','dog')
park=('grant','forest',zoo)
print "the zoo is :",zoo
print "the second animal in zoo is :",park[2][1]
num=len(zoo)
for (i=0;i print zoo[i]
num=len(zoo)
while num>=0:
print zoo[num]
python繼承
----------------------------------
class SchoolMember:
def __init__(self,name,age):
self.name=name
self.age=age
print '(Initialized SchoolMember :%s)' % self.name
def tell(self,name,age):
print 'Name:%s , Age:%s' % (self.name,self.age),
class Student(SchoolMember):
def __init__(self, name,age):
SchoolMember.__init__(self,name,age)
self.salary = salary
print '(Initialized Teacher: %s )' % self.name
python儲存器
--物件持久化,dump----------------------------------
#!/usr/bin/python
import cPickle as p
shopa=['a','aa','aaa']
shopb=('b','bb','bbb')
shopc={'c':129,'cc':132,'ccc':139}
print '''
step 1:
shopa=['a','aa','aaa']
shopb=('b','bb','bbb')
shopc={'c':129,'cc':132,'ccc':139}
'''
persistent_file='/home/tk/persistent.txt'
f=file( persistent_file,'w')
print '''
step 2:
p.dump(shopa,f)
p.dump(shopb,f)
p.dump(shopc,f)
'''
p.dump(shopa,f)
p.dump(shopb,f)
p.dump(shopc,f)
f.close()
f=file(persistent_file)
print '''
step 3:
shopa=p.load(f)
shopb=p.load(f)
shopc=p.load(f)
'''
shopa=p.load(f)
shopb=p.load(f)
shopc=p.load(f)
print shopa,'n',shopb,'n',shopc
---------------------------------------------------[@more@]
二、python基礎
python資料結構:
列表
list=['itemA','itemB','itemC']
元組
array=('itemA','itemB',list)
字典
dict={
'itemA':'valueA',
'itemB':'valueB',
'itemC':'valueC'
}
list的使用:
---------------------------------------------------
arraylist = ['panda','dog','cat','monkey','mouse']
print "the array's length is",len(arraylist)
print "n"
print "the first item is ",arraylist[0]
arraylist.append('snake')
print "nafter add an item 'snake',the array become",
for item in arraylist:
print item
arraylist.sort()
print "nafter sort the array become",
for item in arraylist:
print item,
del arraylist[0]
print "nafter del the first item the array become",arraylist
---------------------------------------------------
元組的使用:
---------------------------------------------------
zoo=('monkey','mouse','tiger','cat','dog')
park=('grant','forest',zoo)
print "the zoo is :",zoo
print "the second animal in zoo is :",park[2][1]
num=len(zoo)
for (i=0;i
num=len(zoo)
while num>=0:
print zoo[num]
python繼承
----------------------------------
class SchoolMember:
def __init__(self,name,age):
self.name=name
self.age=age
print '(Initialized SchoolMember :%s)' % self.name
def tell(self,name,age):
print 'Name:%s , Age:%s' % (self.name,self.age),
class Student(SchoolMember):
def __init__(self, name,age):
SchoolMember.__init__(self,name,age)
self.salary = salary
print '(Initialized Teacher: %s )' % self.name
python儲存器
--物件持久化,dump----------------------------------
#!/usr/bin/python
import cPickle as p
shopa=['a','aa','aaa']
shopb=('b','bb','bbb')
shopc={'c':129,'cc':132,'ccc':139}
print '''
step 1:
shopa=['a','aa','aaa']
shopb=('b','bb','bbb')
shopc={'c':129,'cc':132,'ccc':139}
'''
persistent_file='/home/tk/persistent.txt'
f=file( persistent_file,'w')
print '''
step 2:
p.dump(shopa,f)
p.dump(shopb,f)
p.dump(shopc,f)
'''
p.dump(shopa,f)
p.dump(shopb,f)
p.dump(shopc,f)
f.close()
f=file(persistent_file)
print '''
step 3:
shopa=p.load(f)
shopb=p.load(f)
shopc=p.load(f)
'''
shopa=p.load(f)
shopb=p.load(f)
shopc=p.load(f)
print shopa,'n',shopb,'n',shopc
---------------------------------------------------[@more@]
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/23937368/viewspace-1056200/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- python學習筆記(1Python筆記
- python基礎筆記1Python筆記
- python入門筆記1Python筆記
- Python 筆記-2-1-Python 概述Python筆記
- python基礎筆記0_1Python筆記
- Python筆記_1語法總結Python筆記
- 【python 物件導向】 python物件學習筆記《1》Python物件筆記
- 學習Python的日子 Linux筆記(1)PythonLinux筆記
- Python筆記-CSP 201912-1 報數Python筆記
- Python數模筆記-Sklearn(1) 介紹Python筆記
- Python 學習筆記-2-1-變數Python筆記變數
- Python數模筆記-(1)NetworkX 圖的操作Python筆記
- 筆記1筆記
- python學習筆記1—python的基本資料型別Python筆記資料型別
- fluent python讀書筆記2—Python的序列型別1Python筆記型別
- python筆記Python筆記
- Python機器學習筆記:SVM(1)——SVM概述Python機器學習筆記
- python程式設計學習筆記⑦-1函式Python程式設計筆記函式
- 【Python學習筆記1】Python網路爬蟲初體驗Python筆記爬蟲
- jvm筆記1JVM筆記
- Java筆記1Java筆記
- Day 1 筆記筆記
- Python學習筆記—day1—基礎知識Python筆記
- python筆記(3)Python筆記
- python筆記3Python筆記
- python openpyxl筆記Python筆記
- python筆記-5Python筆記
- Python筆記5Python筆記
- 學習筆記1筆記
- 陣列筆記1陣列筆記
- 閱讀筆記1筆記
- 學習筆記-1筆記
- python筆記(一):序列Python筆記
- Python入門筆記Python筆記
- 筆記:初識Python筆記Python
- 筆記:Python函式筆記Python函式
- python selenium 速查筆記Python筆記
- Python 入門筆記Python筆記
- Python學習筆記Python筆記