機(jī)器學(xué)習(xí)-python數(shù)據(jù)類型詳解_第1頁
機(jī)器學(xué)習(xí)-python數(shù)據(jù)類型詳解_第2頁
機(jī)器學(xué)習(xí)-python數(shù)據(jù)類型詳解_第3頁
機(jī)器學(xué)習(xí)-python數(shù)據(jù)類型詳解_第4頁
已閱讀5頁,還剩7頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

1、1.1、如何在a、使用單引號(hào)str=thisis1.1、如何在a、使用單引號(hào)str=thisisb引號(hào)str=thisisc、使用三引號(hào)str=thisisthisispythodthisis ;thisispythodthisis ;deldelb, 5.3、數(shù)學(xué)5.3、數(shù)學(xué)abs(-10) math.ceil(4.1) cmp(x, y) 如果 x y 返回 1 返回e的x次冪(ex),如math.exp(1) 返回2.718281828459045 返回?cái)?shù)字的絕對(duì)值,如 math.fabs(-10) 返回 10.0floor(x) math.floor(4.9)如math.log(mat

2、h.e)返回 1.0,math.log(100,10)返回 2.0 log10(x) 返回以10為基數(shù)的x的對(duì)數(shù),如math.log10(100)返回2.0 max(x1, x2,.)min(x1, x2,.)xx相同,整數(shù)部分以浮點(diǎn)(x ,base) x 轉(zhuǎn)換為一個(gè)整數(shù) float(x ) 將 x 轉(zhuǎn)換到一個(gè)浮點(diǎn)數(shù) complex(real,imag創(chuàng)建一個(gè)復(fù)數(shù) str(x) 將對(duì)象 x 轉(zhuǎn)換為字符串 tuple(s) s 轉(zhuǎn)換為一個(gè)元組 list(s) 將序列 s 轉(zhuǎn)換為一個(gè)列表 chr(x) 將一個(gè)整數(shù)轉(zhuǎn)換為一個(gè)字符) ord(x) hex(x) oct(x) nums=1,3,5,7,

3、8,13,6.2nums=1,3,5,7,8,13,6.2delnums0;nums:3,5,7,8,13,nums:,len(1,2,3);nums0:nums0:, nums2:5:, nums2:5nums1:3,5,7,8,13,20 從下標(biāo)為1切割到最后一個(gè)元素 nums1:, nums1:nums:-31357 3個(gè)元素,但不包含倒數(shù)第三個(gè)元 nums1,3, 5,7,8,13,20 返回所有元素nums:,(x,yx*y 1,2,3+4,5,6;#1,2,3,4,5,Hi!*4;#Hi!,Hi!,1,2,3+4,5,6;#1,2,3,4,5,Hi!*4;#Hi!,Hi!,Hi!,

4、3in1,2,3#Trueforxin1,2,3:x,#12L=spam,Spam,L2;L-2;L1:;#Spam,list.append(obj) ) list.extend(seq) list.insert(indexobj) list.pop(obj=list-1) 移除列表中的一個(gè)元素(默認(rèn)最后一個(gè)元素)list.remove(obj) list.reverse() list.sort(func) 7、元組tup1=(physics,chemistry,1997,tup2=(1,2,3,4,5 tup3=a,b, c, 創(chuàng)建空元組,例如:tup元組中只有一個(gè)元素時(shí),需要在元素后面添加

5、逗號(hào),例如:tup1tup1=(physics,chemistry,1997,#tup10: 元組中只有一個(gè)元素時(shí),需要在元素后面添加逗號(hào),例如:tup1tup1=(physics,chemistry,1997,#tup10: printtup10:,#tup11:5:(chemistry,printtup11:5:,tup1 = (12, 34.56);tup2=(abc,# #tup10=# tup3 =tup1+printtup3;#(12,34.56,abc, tup=(physics,chemistry,1997,printdelL=(spam,Spam,L2;L-2;L1:;#Sp

6、am,cmp(tuple1,tuple2) len(tuple) max(tuple) uple) L=(spam,Spam,L2;L-2;L1:;#Spam,cmp(tuple1,tuple2) len(tuple) max(tuple) uple) m(seq) dict=Alice:2341,Beth:9102,Cecil:dict1=abc:456dict2=abc:123,98.6:378.2dict=name:Zara,age:7,class:dictname:,dictage:,向字典添加新內(nèi)容的方法是增加新的鍵/值對(duì),修改或刪除已有鍵/值對(duì)如下實(shí)例dict=name:Zara,

7、age:7,class:; #; #dictage:,dictschool:,dict=name:Zara,age:7,class:; #; #dictage:,dictschool:,deldictname; # 刪除鍵是namedict.clear(); # deldict刪除詞典dict=name:Zara,age:7,class:del#dictage:7,class:dict,注意:字典不存在,del cmp(dict1,dict2) len(dict) str(dict) radiansdict.clear() radiansdict.copy() ) ) ) radiansdic

8、t.items() 以列表返回可遍歷的(鍵, 值) radiansdict.keys() radiansdict.setdefault(key, default=None) get()類似, radiansdict.values() import time,localtime radiansdict.values() import time,localtime=#Local current time : time.struct_time(tm_year=2014, tm_mon=3, tm_mday=21, tm_hour=15, tm_min=13, tm_sec=56, tm_wday=4

9、, tm_yday=80, tm_isdst=0)Localcurrenttime:,time.struct_time(tm_year=2014, tm_mon=3, tm_mday=21, tm_hour=15, , , , time.strftime(%Y-%m-%d expire_time=2013-05-21 oneday=today= oneday=today= tomorrow=datetime.date.today()+#獲取今天零點(diǎn)的時(shí)間,2014-03-21 # datetime.timedelta(seconds=1),1 # # # #7days,oneday=#今天,2014-03-21today_time=#昨天,2014-03-20yesterday_time=datetime.datetime.now()-#oneday=#今天,2014-03-21today_time=#昨天,2014-03-20yesterday_time=datetime.datetime.now()-#明天,2014-03-22tomorrow_time=dat

溫馨提示

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

評(píng)論

0/150

提交評(píng)論