【黑馬程序員】Python編程學(xué)習(xí)之常用標(biāo)準(zhǔn)庫_第1頁
【黑馬程序員】Python編程學(xué)習(xí)之常用標(biāo)準(zhǔn)庫_第2頁
【黑馬程序員】Python編程學(xué)習(xí)之常用標(biāo)準(zhǔn)庫_第3頁
【黑馬程序員】Python編程學(xué)習(xí)之常用標(biāo)準(zhǔn)庫_第4頁
【黑馬程序員】Python編程學(xué)習(xí)之常用標(biāo)準(zhǔn)庫_第5頁
已閱讀5頁,還剩17頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

+Q1679806262+Q1679806262黑馬程序]Pywwwjtheima,com卜傳喈播程學(xué)下高端IT教育品牌Python/course/273.html71912sxkqqhttps://pan.baidu.eom/s/12-dymJ8FjWzh6b5NKJuP3Qgqlystr='str[0]strstr[3]strstr[0:3]str.find()str='str[0]strstr[3]strstr[0:3]str.find()在則返回字符串首字str.index()在則返回字符串首字str.count()len(str)0。str.replace('串中指定字符數(shù)據(jù)的str.split("",切割數(shù)據(jù)信息;如果切割str.capitalize():str.startswith(串中下標(biāo)為0的串中下標(biāo)為3的串中從下標(biāo)為0strstrstrstrII數(shù)):進(jìn)行指定字符str字符串?dāng)?shù)據(jù)):返回boolen-1strstr否以以指指定d黑嗎程序員否以以指指定d黑嗎程序員傳回booien下高端IT教育品牌str——str.lower()str.upper()str.ljust(的字符串長度):返回一個字符串,將strstr充操作。str.rjust(度):返strstr充操作。str.center(長度):strstrstr.lstrip()空格。str.rstrip()空格。str.rfind()findstr.rindex()符的下標(biāo)。indexstrstr.partition(標(biāo)。串):從strstr.rpartition(串):下空字符。partitionstr.splitlines():。的。str.isdigit()字。boolenstrstr.isalpha()boolenstrstr.isalnum()boolenstr空格格。。^黑馬程boo員wwwJtheima,comstr.isupper()boolen傳智播客旗不高端IT教育品牌-str-str.islower()boolenstr寫。strmystr.join(str)mystr作;返回拼接后的字符串?dāng)?shù)據(jù)信息。strprint("%0.1f",float(result*1.0))的數(shù)據(jù)print("%d*%d=%d"%(j,i,i*j),end=''):結(jié)束最后的2、文件流文件流對應(yīng)的基礎(chǔ)操作:f=open('','')iffboolen開。w果該文件不存在,則創(chuàng)建一個新的文件。r默認(rèn)模式。arb:wbab:傳智播客旗下傳智播客旗下高端文件教育品牌傳智播客旗下傳智播客旗下高端文件教育品牌+Q1679806262+Q1679806262黑馬程序員r+ww.itheim文件omw+a+rb+:wb+ab+f.close()f.wirte()f.read()readf.readline()f.readlines()素為一行數(shù)據(jù)的信息。f.tell()seek(offset,from)from0:表示文件的開頭。1:表示文件的當(dāng)前位置。2:表示文件的末尾。offset測試f.seek(5,0)5傳傳智播移3s下高端IT教育品牌傳傳智播移3s下高端IT教育品牌+Q1679806262+Q1679806262黑河黑河程序員wwwJ1、列表:strList=['']str=''newStr=''strList.appendstrList[0]=newStrstrinstrLsitboolenforiteminstrListitemdelstrList[0]strList.pop()strList.remove('')2、字典:Keyinfor['age']=18delinfor.clear3、字典的常見操作dic={1:'xiaohao',2:'xiaodong'}dic.keys()dic.valuses()dic.items()組,分別存放著鍵和值。dic.has_key(1)boolen4、元組:tuple=(1,2,3,4,5)+Q1679806262+Q16798062621黑馬程序員1e[-2:theima.8m傳智播客旗下高端1丁教育品牌tuple[1:]cmp(tuple1,tuple2)max(tuple)min(tuple)tuple(seq)5、運算符操作列表、字典、11en((1,2,3,4))2、(1,2,3,4)+(1,2,3,4,5)3['Hi']*4boolen4、1in(1,2,3,4):判斷元boolen4、異常捕獲定義:某些錯誤操作導(dǎo)致程序無法正常運行異常捕獲:try:except(NameError,IOError),result:print(result)#else:print("else")finally:print("finally")range1、help(range):range(stop)->listofintegersrange(start,stop[,step])->listofintegers2、參數(shù)分析:start:start0range53,4]5e(0黑馬程序員W.itStOpr結(jié)束,但傳智播客旗下高磷o(hù)p教育電相e05[0,1,2,1range051range05range(0,5,1)。3、示教:a=range(5)list(a)map1、help(map):map(...)map(function,sequence[,sequence,...])->list2、參數(shù)分析:function:sequence:,functionlist3、語法:functionfunctionlist4、示教函數(shù)需要一個參數(shù)map(lambdax:x*x,[1,2,3])[1,4,9]函數(shù)需要兩個參數(shù)map(lambdax,y:x+y,[1,2,3],[4,5,6])[5,7,9]None,map(None,[1,3,5,7,9],[2,4,6,8,10])

#2),⑶4),(5,6),(7,8),(9,10)]百客旗下wwwJtheima,com?高端IT教育品牌#Nonemap(None,[1,3,5,7,9],[2,4,6])[(1,2),(3,4),(5,6),(7,None),(9,None)]filter1、help(filter):filter(...)filter(functionorNone,sequence)->list,tuple,orstringReturnthoseitemsofsequenceforwhichfunction(item)istrue.IffunctionisNone,returntheitemsthataretrue.Ifsequenceisatupleorstring,returnthesametype,elsereturnalist.2、參數(shù)分析:function:TrueFalsesequence:strtuplelist3、語法filtersequencefunctionTruesequence類型相同4、示例filter(lambdax:x%2,[1,2,3,4])[1,3]filter(None,"she")'she'reduce1、help(reduce):

ce(…)ce(…)u傳智播客旗下Lnce新niyM育弼乳Applyafunctionoftwoargumentscumulativelytotheitemsofasequence,fromlefttoright,soastoreducethesequencetoasinglevalue.Forexample,reduce(lambdax,y:x+y,[1,2,3,4,5])calculates((((1+2)+3)+4)+5).Ifinitialispresent,itisplacedbeforetheitemsofthesequenceinthecalculation,andservesasadefaultwhenthesequenceisempty.2、參數(shù)分析:function:sequence:strtuplelistinitial:3、語法reducesequencefunctionfunctionfunctioninitialsequenceinitialfunctionsequencefunctionfunctionNone4、示例reduce(lambdax,y:x+y,[1,2,3,4])10reduce(lambdax,y:x+y,[1,2,3,4],5)15reduce(lambdax,y:x+y,['aa','bb','cc'],'dd')傳智傳智播客旗下python高端IT教育品牌傳智傳智播客旗下python高端IT教育品牌+Q1679806262+Q1679806262(fX'ddaabbcc'wwwJ9sorted1、help(sorted):sorted(...)sorted(iterable,cmp=None,key=None,reverse=False)-->newsortedlist2、參數(shù)分析:cmpx<y返回-1x>y返回1x==y返回03、示例defcmp_ignore_case(s1,s2):u1=s1.upper()u2=s2.upper()ifu1<u2:return-1ifu1>u2:return1return1print()raw_input()2、用戶自定義函數(shù):如果系統(tǒng)中,3ipythondir()幺簿黑馬程序員^^^名.ahitheim獲.combuilinsoswidows'nt'Linux'posixTrueFalseTrueFalsewidows'nt'Linux'posixTrueFalseTrueFalseTrueFalseos.system()shellos.chdir()os.path.getsize()os.path.abspath()ospath.join(path,name)ospath.basename(path)ospath.dirname(path):sys:Python傳智傳智播客旗下python高端IT教育品牌st')st')智播客旗下高端IT教育品牌+Q1679806262+Q1679806262傳mport黑馬程序員sys.stdinsys.argvfunctools:1、概念:functoolspython2.52、操作:1、importfunctools:2、dir(functools):查看partial1、概念:2、示例:importfunctoolsdefshowarg(*args,**kw):print(args)print(kw)p1=functools.partial(showarg,1,2,3)p1()p1(4,5,6)p1(a='python',b='itcast')p2=functools.partial(showarg,a=3,b='linux')p2()p2(1,2)IGp2(a='Python',b='^wwwJtheima,com?wraps1、概念:Pythonfunctoolswrapsimportfunctoolsdefnote(func):"notefunction"@functools.wraps(func)defwrapper():"wrapperfunction"print('notesomething')returnfunc()returnwrapper@notedeftest():"testfunction"print('Iamtest')test()print(test.__doc__)jsonJSONjsonlogging黑馬程序員wwwJfork/multiprocessingimportos1、pid=os.fork()os.fork()fork()的idfock()Unix/Linux/Mac0,而父進(jìn)程中windowsimportosforkUnix/Linux/Macwindowspid=os.fork()ifpid==0:print('else:print('1')2')os.getpid():os.getppid()PIDPID2、進(jìn)程創(chuàng)建的第二種方式:frommultiprocessingimportProcessp=Process(target=run_proc,args=('test',))

targetProcessargsp.start()傳傳可播客旗下高端IT教育品牌傳傳可播客旗下高端IT教育品牌+Q1679806262+Q1679806262)黑馬程序員火程間的同cpumultiprocessing.cpu_count()cpupipe=multiprocessing.Pipe()pipe[0]pipe[1]pipe[0].send()pipe[0].recv()3、frommultiprocessingimportProcess,Queueq=Queue()q.put()q.get(True)q.empty()threadingthreadimportthreadthread.start_new_thread(defName,())參數(shù)為新線程要執(zhí)行的方法,第二個參數(shù)為元組傳遞執(zhí)行方法對python(,)''thread.exit_thread()exit.thread()thread.join()pythonThreadjoin()線程可播等待另一個線程執(zhí)行結(jié)束后再繼續(xù)運行。這個方法還timeout傳智播客旗下傳智播客旗下高端1丁教育品牌傳智播客旗下傳智播客旗下高端1丁教育品牌+Q1679806262+Q1679806262黑馬程序員ad.setDaemon(True)threadingthread裝,可以更方便我們的使用。importthreadingmyThread=threading.Thread(target=defName,args=('Alice',))targetargsmyThread.start()num=len(threading.enumerate)threading.Theaddefrun(self):classMyThread(threading.Thread)進(jìn)行基類構(gòu)造函數(shù)的創(chuàng)建操作def__init__(self,name,time):threading.Thread.__init__(self,name='')myThread=MyThread()myThread.start()threadingLock()mutex=threading.Lock()ifmutex.acquire([blocking])trueacquire。blockingblockingTrueTrueblockingFalseea程序員ea程序員wwwJ傳智播客旗的高端IT教育品牌ea程序員ea程序員wwwJ傳智播客旗的高端IT教育品牌+Q1679806262+Q16798062625pythonRLockLockcountercounteracquire

5pythonRLockLockcountercounteracquire

acquireacquirereleasemutex=threading.RLock()mutex.acquire()mutex.release()6pythonConditionConditionConditionwaitingcon=threading.Condition()Lock/RLockRLockcon.acquire()con.wait()Conditionblockedwaitingcon.notify()Conditionwaitingacquirecon.notifyAll():Condition對象通知waiting池中所有的線程acquirecon.release()threading.EventFalsewait()set()TrueEventisSet()Eventevent=threading.Event()Enventdef__init__(self,threadName,event):self.threadEvent=event:重構(gòu)對應(yīng)threading.Threadinit的方法。傳智傳智播客旗下中端待的教育品牌傳智傳智播客旗下中端待的教育品牌+Q1679806262+Q1679806262?t黑adE程序受他set():啟動超位哂QueuefromQueueimportQueuequeue=Queue()queue.qsize()queue.put()queue.set()queue.empty()copytimedatetimeTOC\o"1-5"\h\zcalendar——hashlib-randomimportrandomrandom.random()01傳傳智播獲旗下翥之間教育品牌傳傳智播獲旗下翥之間教育品牌+Q1679806262+Q1679806262傷呼嘿畫程序員57ondOmirandint(10.50):r0到TOC\o"1-5"\h

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論