山東大學Python(3) 容器

2021-10-01 03:45:26 字數 3451 閱讀 6169

#%%

# 使用 jupyter notebook 編寫

"""本章知識目錄:

本節非常簡單,看ppt即可,下面的**為一些測試

""""""

考試:(非常重要)

查詢、增加、刪除、引用

ppt所有的都要看

"""#%%

"""list:

list_name.remove(x):刪除首次出現的值為x的元素,x不存在則丟擲異常

del list_name[index]:刪除索引為index的元素

list_name.pop(index):刪除索引為index的元素

list_name.insert(index, x):在index處,新增x

list_name.index(x):獲取指定元素x首次出現的索引,不存在則丟擲異常

x in list_name:x在list_name中返回true,否則返回false

x not in list_name:x不在list_name中返回true,否則返回false

len(list_name):獲取列表長度

dict:

dict_name.fromkeys(list_name):以list_name為鍵創造值為none的字典

del dict_name:刪除整個字典

dict_name.get(key):返回鍵為key的值,若不存在key,則建立該鍵值為none並返回none

dict_name.get(key, value):返回鍵為key的值,若不存在key,則建立該鍵值為value並返回value

key in dict_name:key在dict_name中返回true,否則返回false

dict_name.has_key(key):含有key返回true,否則返回false

dict_name.keys():以列表的形式返回所有的keys

dict_name.values():以列表的形式返回所有的values

dict_name.items():以列表的形式返回值為(key, value)的所有鍵值對

dict_name1.update(dict_name2):將dict_name2新增到dict_name1中,若key相同,則覆蓋

del dict_name[key]:刪除key所對應的元素

dict_name.clear():清空字典中的所有鍵值對,使之成為空字典

dict_name.pop(key):刪除指定鍵並返回指定鍵的元素

dict_name.popitem():隨機刪除乙個鍵值對,並返回該鍵值對的值

"""#%%

kobe_list =[2

,'面向'

,false

,3.14

,none

]print

(kobe_list)

print

(type

(kobe_list)

)'end'

)print

(kobe_list)

kobe_list.remove(

3.14

)print

(kobe_list)

temp = kobe_list

del kobe_list[0]

print

(kobe_list)

kobe_list = temp

print

(kobe_list)

kobe_list.pop(-1

)print

(kobe_list)

kobe_list.insert(-1

,'end'

)print

(kobe_list)

kobe_list.insert(0,

34)print

(kobe_list)

print(3

in kobe_list)

#%%alist =[3

,4,5

,6]blist =

['a'

,'b'

,'c'

]for a, b in

zip(alist, blist)

:print

(a, b)

print

(type

(zip

(alist, blist)))

print

(len

(alist)

)#%%

print

(kobe_list)

print

(kobe_list[1:

4])# ppt第15頁的下面的,標著索引,看好-1和6的位置

#%%atuple =

('first',)

print

(type

(atuple)

)print

(atuple)

btuple =()

print

(type

(btuple)

)ctuple =

tuple()

print

(type

(ctuple)

)print

(tuple

(alist)

)print

(alist)

del ctuple

#%%azip =[1

,2,3

]bzip =

['a'

,'b'

,'c'

,'d'

]czip =

zip(azip, bzip)

print

(czip)

print

(list

(czip)

)tempzip =[(

1,'a'),(

2,'b')

]print

(tempzip)

print

(zip

(tempzip)

)#%%

adict =

# 後乙個key為1的值'g'把前面的覆蓋了

print

(type

(adict)

)print

(adict)

bdict =

dict

(czip)

print

(dict

(zip

(alist, blist)))

cdict =

dict

(name=

3, age=

'old'

)print

(cdict)

ddict =

dict

.fromkeys(

['name'

,'age'

,'***'])

print

(ddict)

del ddict

山東大學Python(1) Python基礎

使用 jupyter notebook 編寫 本章知識目錄 1.python的特性 2.python的用途 3.限制python發展的因素 4.python的缺點 考試 python的特性 限制python的發展因素 python的特性 1.互動式命令列 2.不只是指令碼 3.強大易用的標準庫 4....

山東大學 資料科學導論 期末

一.簡答 1.dirty data在哪些過程怎麼產生 2.解釋entity resolution 3.兩個向量,計算距離 歐式,曼哈頓,漢明,切比雪夫,余弦 二.好像也是簡答?1.mapreduce 1 設計map和reduce方法實現表自然連線 2 兩個表的例項,根據表寫mapreduce自然連線...

山東大學學報稿件查詢

查詢稿件狀態並上傳郵箱,很多國內期刊模板一致隨意改動 coding utf 8 time 2019 12 1 22 17 author yemanzhongting email sggzhang whu.edu.cn file 1.py software pycharm usr bin python...