av激情亚洲男人的天堂国语,日韩欧美精品一中文字幕,无码av一区二区三区无码,国产又色又爽又刺激的a片,国产又色又爽又刺激的a片

創(chuàng)新互聯(lián)Python教程:python中的三種推導式介紹

1、列表推導式,在一個中括號里包含一個表達式。

創(chuàng)新互聯(lián)建站專業(yè)為企業(yè)提供菏澤網(wǎng)站建設、菏澤做網(wǎng)站、菏澤網(wǎng)站設計、菏澤網(wǎng)站制作等企業(yè)網(wǎng)站建設、網(wǎng)頁設計與制作、菏澤企業(yè)網(wǎng)站模板建站服務,十余年菏澤做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡服務。

old_list = [0,1,2,3,4,5]
new_list = []
for item in old_list:
    if item % 2 == 0:
        new_list.append(item)
 
print(new_list)

2、字典推導式,把[]改成了{},并且組成元素有key和value。

old_student_score_info = {
    "Jack": {
        "chinese": 87,
        "math": 92,
        "english": 78
    },
    "Tom": {
        "chinese": 92,
        "math": 100,
        "english": 89
    }
}
new_student_score_info = {}
for name, scores in old_student_score_info.items():
    if scores["math"] == 100:
        new_student_score_info.setdefault(name, scores)
print(new_student_score_info)

3、集合推導式跟使用大括號{},組成元素也只要一個。

old_list = [0, 0, 0, 1, 2, 3]
 
new_set = {item for item in old_list}
print(new_set)

以上就是python中的三種推導式介紹,希望對大家有所幫助。更多Python學習指路:創(chuàng)新互聯(lián)Python教程

本文教程操作環(huán)境:windows7系統(tǒng)、Python 3.9.1,DELL G3電腦。


網(wǎng)站題目:創(chuàng)新互聯(lián)Python教程:python中的三種推導式介紹
轉(zhuǎn)載注明:http://uogjgqi.cn/article/dpihjoj.html
掃二維碼與項目經(jīng)理溝通

我們在微信上24小時期待你的聲音

解答本文疑問/技術咨詢/運營咨詢/技術建議/互聯(lián)網(wǎng)交流