99999久久久久久亚洲,欧美人与禽猛交狂配,高清日韩av在线影院,一个人在线高清免费观看,啦啦啦在线视频免费观看www

熱線電話:13121318867

登錄
首頁精彩閱讀python的dict,set,list,tuple應(yīng)用詳解
python的dict,set,list,tuple應(yīng)用詳解
2018-04-16
收藏

python的dict,set,list,tuple應(yīng)用詳解

本文深入剖析了python中dict,set,list,tuple應(yīng)用及對應(yīng)示例,有助于讀者對其概念及原理的掌握。具體如下:

1.字典(dict)
dict 用 {} 包圍
dict.keys(),dict.values(),dict.items()
hash(obj)返回obj的哈希值,如果返回表示可以作為dict的key
del 或 dict.pop可以刪除一個item,clear清除所有的內(nèi)容
sorted(dict)可以把dict排序
dict.get()可以查找沒存在的key,dict.[]不可以
dict.setdefault() 檢查字典中是否含有某鍵。 如果字典中這個鍵存在,你可以取到它的值。 如果所找的鍵在字典中不存在,你可以給這個鍵賦默認(rèn)值并返回此值。
{}.fromkeys()創(chuàng)建一個dict,例如:    
{}.fromkeys(('love', 'honor'), True) =>{'love': True, 'honor': True}
不允許一個鍵對應(yīng)多個值
鍵值必須是哈希的,用hash()測試
一個對象,如果實(shí)現(xiàn)_hash()_方法可以作為鍵值使用
2.集合(set)
集合是一個數(shù)學(xué)概念,用set()創(chuàng)建
set.add(),set.update.set.remove,添加更新刪除,-= 可以做set減法
set.discard 和 set.remove不同在于如果刪除的元素不在集合內(nèi),discard不報(bào)錯,remove 報(bào)錯
< <= 表示 子集,> >=表示超集
| 表示聯(lián)合 & 表示交集 - 表示差集 ^ 差分集
3.列表(list)
列表是序列對象,可包含任意的Python數(shù)據(jù)信息,如字符串、數(shù)字、列表、元組等。列表的數(shù)據(jù)是可變的,我們可通過對象方法對列表中的數(shù)據(jù)進(jìn)行增加、修改、刪除等操作??梢酝ㄟ^list(seq)函數(shù)把一個序列類型轉(zhuǎn)換成一個列表。
append(x) 在列表尾部追加單個對象x。使用多個參數(shù)會引起異常。
count(x) 返回對象x在列表中出現(xiàn)的次數(shù)。
extend(L) 將列表L中的表項(xiàng)添加到列表中。返回None。
Index(x) 返回列表中匹配對象x的第一個列表項(xiàng)的索引。無匹配元素時(shí)產(chǎn)生異常。
insert(i,x) 在索引為i的元素前插入對象x。如list.insert(0,x)在第一項(xiàng)前插入對象。返回None。
pop(x) 刪除列表中索引為x的表項(xiàng),并返回該表項(xiàng)的值。若未指定索引,pop返回列表最后一項(xiàng)。
remove(x) 刪除列表中匹配對象x的第一個元素。匹配元素時(shí)產(chǎn)生異常。返回None。
reverse() 顛倒列表元素的順序。
sort() 對列表排序,返回none。bisect模塊可用于排序列表項(xiàng)的添加和刪除。
4.元組(tuple)
tuple=(1,),這是單個元素的元組表示,需加額外的逗號。
tuple=1,2,3,4,這也可以是一個元組,在不使用圓括號而不會導(dǎo)致混淆時(shí),Python允許不使用圓括號的元組。
和列表一樣,可對元組進(jìn)行索引、分片、連接和重復(fù)。也可用len()求元組長度。
元組的索引用tuple[i]的形式,而不是tuple(i)。
和列表類似,使用tuple(seq)可把其它序列類型轉(zhuǎn)換成元組。

數(shù)據(jù)分析咨詢請掃描二維碼

若不方便掃碼,搜微信號:CDAshujufenxi

數(shù)據(jù)分析師資訊
更多

OK
客服在線
立即咨詢
客服在線
立即咨詢
') } function initGt() { var handler = function (captchaObj) { captchaObj.appendTo('#captcha'); captchaObj.onReady(function () { $("#wait").hide(); }).onSuccess(function(){ $('.getcheckcode').removeClass('dis'); $('.getcheckcode').trigger('click'); }); window.captchaObj = captchaObj; }; $('#captcha').show(); $.ajax({ url: "/login/gtstart?t=" + (new Date()).getTime(), // 加隨機(jī)數(shù)防止緩存 type: "get", dataType: "json", success: function (data) { $('#text').hide(); $('#wait').show(); // 調(diào)用 initGeetest 進(jìn)行初始化 // 參數(shù)1:配置參數(shù) // 參數(shù)2:回調(diào),回調(diào)的第一個參數(shù)驗(yàn)證碼對象,之后可以使用它調(diào)用相應(yīng)的接口 initGeetest({ // 以下 4 個配置參數(shù)為必須,不能缺少 gt: data.gt, challenge: data.challenge, offline: !data.success, // 表示用戶后臺檢測極驗(yàn)服務(wù)器是否宕機(jī) new_captcha: data.new_captcha, // 用于宕機(jī)時(shí)表示是新驗(yàn)證碼的宕機(jī) product: "float", // 產(chǎn)品形式,包括:float,popup width: "280px", https: true // 更多配置參數(shù)說明請參見:http://docs.geetest.com/install/client/web-front/ }, handler); } }); } function codeCutdown() { if(_wait == 0){ //倒計(jì)時(shí)完成 $(".getcheckcode").removeClass('dis').html("重新獲取"); }else{ $(".getcheckcode").addClass('dis').html("重新獲取("+_wait+"s)"); _wait--; setTimeout(function () { codeCutdown(); },1000); } } function inputValidate(ele,telInput) { var oInput = ele; var inputVal = oInput.val(); var oType = ele.attr('data-type'); var oEtag = $('#etag').val(); var oErr = oInput.closest('.form_box').next('.err_txt'); var empTxt = '請輸入'+oInput.attr('placeholder')+'!'; var errTxt = '請輸入正確的'+oInput.attr('placeholder')+'!'; var pattern; if(inputVal==""){ if(!telInput){ errFun(oErr,empTxt); } return false; }else { switch (oType){ case 'login_mobile': pattern = /^1[3456789]\d{9}$/; if(inputVal.length==11) { $.ajax({ url: '/login/checkmobile', type: "post", dataType: "json", data: { mobile: inputVal, etag: oEtag, page_ur: window.location.href, page_referer: document.referrer }, success: function (data) { } }); } break; case 'login_yzm': pattern = /^\d{6}$/; break; } if(oType=='login_mobile'){ } if(!!validateFun(pattern,inputVal)){ errFun(oErr,'') if(telInput){ $('.getcheckcode').removeClass('dis'); } }else { if(!telInput) { errFun(oErr, errTxt); }else { $('.getcheckcode').addClass('dis'); } return false; } } return true; } function errFun(obj,msg) { obj.html(msg); if(msg==''){ $('.login_submit').removeClass('dis'); }else { $('.login_submit').addClass('dis'); } } function validateFun(pat,val) { return pat.test(val); }