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

熱線電話:13121318867

登錄
首頁精彩閱讀Python學(xué)習(xí)-語句、語法
Python學(xué)習(xí)-語句、語法
2017-03-16
收藏

Python學(xué)習(xí)-語句、語法

#: 注釋,不支持多行注釋

\:  連接,當(dāng)一行的程序太長時(shí),可以使用連接符\(反斜杠)

1、使用if、elif 和 else 進(jìn)行標(biāo)記

小于兩個(gè)的選擇:

if  條件 :

語句段1

else :

語句段2

大于兩個(gè)的選擇:

if 條件1 :

語句段1

elif  條件2 :

語句段2

else :

語句段3


2、使用while進(jìn)行循環(huán)

while 條件:

語句段1

else:            # 可選

語句段2

break: 跳出循環(huán)

continue:跳到循環(huán)開始


3、使用for迭代

for 變量 in 可迭代的對象

元組或列表在一次迭代過程產(chǎn)生一項(xiàng),而字符串迭代會(huì)產(chǎn)生一個(gè)字符,對一個(gè)字典進(jìn)行迭代將返回字典中的鍵。想對字典中的值進(jìn)行迭代,可使用values()函數(shù):

for value in accusation.values():

print(value)

為了以元組的形式返回鍵值對,可以使用字典的items() 函數(shù):

for item in accusation.items():

print(item)


4、使用zip()并行迭代

zip()函數(shù)在最短序列“用完”時(shí)就會(huì)停止

5、使用range()生成自然數(shù)序列

range()函數(shù)的用法類似于使用切片:range(start、stop、step),start的默認(rèn)值為0,唯一要求的參數(shù)值是stop,產(chǎn)生的最后一個(gè)數(shù)的值是stop的前一個(gè),并且step的默認(rèn)值是1。

例:得到從0到10的偶數(shù)

list(range(0,10,2))

推導(dǎo)式

從一個(gè)或多個(gè)迭代器快速簡潔地創(chuàng)建數(shù)據(jù)結(jié)構(gòu)的一種方法。

列表推導(dǎo)式1:最簡單表示形式如下:

[expression for item in iterable]

例:將通過列表推導(dǎo)創(chuàng)建一個(gè)整數(shù)列表:

>>> number_list = [number for number in range(1,6)]

>>> number_list

[1,2,3,4,5]

第一個(gè)number變量為列表生成值,也就是說,把循環(huán)的結(jié)果放在列表number_list中

第二個(gè)number為循環(huán)變量,其中 第一個(gè)number 可以為表達(dá)式


列表推導(dǎo)式2:表示形式如下:

[expression for item in iterable if condition]


>>> rows = range(1,4)

>>> cols = range(1,3)

>>> cells = [(row,col) for row in rows for col in cols]

>>> for cell in cells:

print(cell)



(1, 1)

(1, 2)

(2, 1)

(2, 2)

(3, 1)

(3, 2)

>>> 


字典推導(dǎo)式:表達(dá)式如下:

{ key_expression : value_expression for expression in iterable }


>>> word = 'letters'

>>> letter_counts = {letter: word.count(letter) for letter in set(word)}

>>> letter_counts

{'s': 1, 'r': 1, 't': 2, 'e': 2, 'l': 1}

>>> 

集合推導(dǎo)式:表達(dá)式如下:

{ expression for expression in iterable }


>>> a_set = {number for number in range(1,6) if number % 3 == 1}

>>> a_set

{1, 4}


生成器推導(dǎo)式:

元組沒有推導(dǎo)式,列表推導(dǎo)式的方括號(hào)變?yōu)閳A括號(hào)后,圓括號(hào)之間的是生成器推導(dǎo)式,它返回的是一個(gè)生成器對象,生成器僅在運(yùn)行中產(chǎn)生值,一個(gè)生成器只能運(yùn)算一次,不能重新使用或備份。數(shù)據(jù)分析師培訓(xùn)

>>> number_thing = (number for number in range(1,6))

>>> type(number_thing)

<class 'generator'>

>>> number_list = list(number_thing)

>>> number_list

[1, 2, 3, 4, 5]

>>> try_again = list(number_thing)

>>> try_again

[]

>>>

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

若不方便掃碼,搜微信號(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)證碼對象,之后可以使用它調(diào)用相應(yīng)的接口 initGeetest({ // 以下 4 個(gè)配置參數(shù)為必須,不能缺少 gt: data.gt, challenge: data.challenge, offline: !data.success, // 表示用戶后臺(tái)檢測極驗(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); }