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

熱線電話:13121318867

登錄
首頁精彩閱讀Python編程之列表操作實(shí)例詳解【創(chuàng)建、使用、更新、刪除】
Python編程之列表操作實(shí)例詳解【創(chuàng)建、使用、更新、刪除】
2018-03-20
收藏

Python編程之列表操作實(shí)例詳解【創(chuàng)建、使用、更新、刪除】

這篇文章主要介紹了Python編程之列表操作,結(jié)合實(shí)例形式分析了Python列表的創(chuàng)建、使用、更新、刪除等實(shí)現(xiàn)方法與相關(guān)操作技巧,需要的朋友可以參考下

#coding=utf8
'''''
列表類型也是序列式的數(shù)據(jù)類型,
可以通過下標(biāo)或者切片操作來訪問某一個(gè)或者某一塊連續(xù)的元素。
列表不僅可以包含Python的標(biāo)準(zhǔn)類型,
而且可以用用戶定義的對(duì)象作為自己的元素。
列表可以包含不同類型的對(duì)象,
列表可以執(zhí)行pop、empt、sort、reverse等操作。
列表可以添加或者減少元素,
還可以與其他列表結(jié)合或者把一個(gè)列表拆分成幾個(gè)。
可以對(duì)一個(gè)元素或者多個(gè)元素執(zhí)行insert、update或者remove操作。
元組和列表主要不同之處在于,前者不可變(只讀),
那些用于更新列表的操作,就不能用于元組類型。
列表是由方括號(hào)([])來定義的,也可以用工廠方法list()創(chuàng)建它。
可以通過在等號(hào)左邊指定一個(gè)索引或者索引范圍的方式來更新一個(gè)或幾個(gè)元素,
也可以通過append()方法追加元素到列表中去。
要?jiǎng)h除列表中的元素,如果確切知道要?jiǎng)h除元素的索引可以用del語句,
否則可以用remove()方法。
還可以通過pop()方法來刪除并從列表中返回一個(gè)特定對(duì)象。
一般來說,程序員不需要去刪除一個(gè)列表對(duì)象引用。
列表對(duì)象出了作用域后它會(huì)自動(dòng)被析構(gòu),但如果想刪除一整個(gè)列表,可以使用del語句。
'''
#創(chuàng)建列表
oneList=["one",1,2,23.6,"two"]
#通過工廠函數(shù)創(chuàng)建list
twoList=list("hello world")
#創(chuàng)建一個(gè)初始化的表
threeList=[]
#輸出列表中的內(nèi)容
print oneList,"\n",twoList
#訪問列表中的元素
#通過索引訪問
print oneList[0],oneList[-1]
#通過切片訪問,默認(rèn)間隔為1
print twoList[0:2]
#通過切片訪問,設(shè)置間隔為2
print twoList[0:5:2]
#更新列表中的元素
#通過索引更新元素
oneList[0]="One"
print oneList[0]
#通過切片更新幾個(gè)元素
twoList[0:5]=[1,2,3,4,5]
print twoList[0:5]
#調(diào)用append()方法,向list中追加元素
threeList.append(oneList)
threeList.append("hello")
print threeList
#刪除列表中的元素或列表本身
#del刪除列表中某一元素
print len(twoList)
del twoList[5]
print len(twoList),twoList[5]
#remove刪除列表中某一元素
print len(threeList)
threeList.remove("hello")
print len(threeList),threeList
#pop刪除列表最后一個(gè)元素
#并把刪除的元素保存為一個(gè)對(duì)象
print oneList.pop(),oneList
#使用切片刪除一定范圍內(nèi)的元素
print twoList
del twoList[0:4]
print twoList
#刪除一個(gè)列表引用
print twoList
try:
  del twoList
  print twoList
except Exception,e:
  print "twoList not exists"

運(yùn)行結(jié)果:


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

若不方便掃碼,搜微信號(hào):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)的第一個(gè)參數(shù)驗(yàn)證碼對(duì)象,之后可以使用它調(diào)用相應(yīng)的接口 initGeetest({ // 以下 4 個(gè)配置參數(shù)為必須,不能缺少 gt: data.gt, challenge: data.challenge, offline: !data.success, // 表示用戶后臺(tái)檢測(cè)極驗(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ù)說明請(qǐng)參見: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 = '請(qǐng)輸入'+oInput.attr('placeholder')+'!'; var errTxt = '請(qǐng)輸入正確的'+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); }