神经网络与深度学习——TensorFlow2.0实战(笔记)(四)(python字典和集合)
生活随笔
收集整理的這篇文章主要介紹了
神经网络与深度学习——TensorFlow2.0实战(笔记)(四)(python字典和集合)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
字典和集合
字典
每個字典元素都是一個鍵(關鍵字)/值(關鍵字對應的取值)對
#創建字典 dic_score={"語文":80,"數學":99} #打印 print(dic_score) print(dic_score["語文"]) #長度 print(dic_score.__len__)#錯誤寫法 print(len(dic_score)) #存在判斷是否存在 in print("語文" in dic_score) """ keys()返回字典中所有關鍵字 values()返回字典中所有值 items()返回字典中所有鍵值對 """ #遍歷 for key in dic_score.keys():print(key) for value in dic_score.values():print(value) for item in dic_score.items():print(item) """ 字典中的各個元素是無序的,因此每次顯示的順序可能不同 添加元素 賦值語句 修改指定元素 賦值語句 合并字典 字典.update(字典) 刪除字典 pop(指定元素的關鍵字) 刪除所有元素clear() del語句 """ dic_student={'name':'張明','sex':'男'} #添加 dic_student['score']=98 print("添加元素",dic_student) #修改 dic_student['score']=90 print("修改指定元素",dic_student) #合并 dic_student.update(dic_score) print("合并字典",dic_student) #刪除指定 dic_student.pop("sex") print("刪除指定",dic_student) #刪除所以 dic_student.clear() print("刪除所以",dic_student)集合
集合:一組無序排列的元素組成,因此不能通過下標來訪問
可變集合:創建后可以添加、修改和刪除其中的元素
不可變集合:創建后就不能再改變了
#創建 set12={1,2} print(set12) print(len(set12)) #可變集合 set_python=set("python") print(set_python) #不可變集合 frozenset_python=frozenset("python") print(frozenset_python)課程鏈接:https://www.icourse163.org/course/XUST-1206363802?tid=1206674203
個人公眾號
總結
以上是生活随笔為你收集整理的神经网络与深度学习——TensorFlow2.0实战(笔记)(四)(python字典和集合)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 比亚迪市值破万亿有多猛?“股神”巴菲特获
- 下一篇: python中安装opencv一直说不是