2.字典实例 #coding=utf-8#创建空字典dictionary1={}print(type(dictionary1))#多元素字典dictionary1 = {'age':18,'name':'tom',11:22,12.5:3.1415};#取值print(dictionary1["age"],dictionary1["name"])print(dictionary1)#根据健,修改值dictionary1["age"]=28print(dictionary1["age"])#添加值,字典...
# -- coding: utf-8 -- # @time : 2022/7/19 21:51 # @file : 10pytest基本数据类型-dic.py # @software: pycharm D = {"a": "123", "b": "456", "c": 888} D.copy() print(id(D)) print(id(D.copy())) print(D.copy()) # D的浅拷贝 print(D.get("a")) # 获取key为...
#!/usr/bin/python # -*- coding: UTF-8 -*- dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'} del dict['Name'] # 删除键是'Name'的条目 dict.clear() # 清空字典所有条目 del dict # 删除字典 print ("dict['Age']: ", dict['Age'])print ("dict['School']: ", dict...
二.Tumple 1#coding=utf-82t = ('a','b','c','d','e')3printtype(t)#<type 'tuple'>4printt#('a', 'b', 'c', 'd', 'e')5print(0, 1, 2) < (0, 3, 4)#True6print(0, 1, 2000000) < (0, 3, 4)#True7"""8比较运算符适用于元组和其它序列, Python从每个序列的第一个...
#!/usr/bin/python # -*- coding: UTF-8 -*- dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'} del dict['Name'] # 删除键是'Name'的条目 dict.clear() # 清空字典所有条目 del dict # 删除字典 print "dict['Age']: ", dict['Age'] print "dict['School']: ", dict['Sch...
#!/usr/bin/python # -*- coding: UTF-8 -*- dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'} del dict['Name'] # 删除键是'Name'的条目 dict.clear() # 清空字典所有条目 del dict # 删除字典 print "dict['Age']: ", dict['Age'] print "dict['School']: ", dict['Sch...
File "test.py", line 5, in <module> print "tinydict['Alice']: ", tinydict['Alice'] KeyError: 'Alice' 修改字典 向字典添加新内容的方法是增加新的键/值对,修改或删除已有键/值对如下实例: 实例 #!/usr/bin/python # -*- coding: UTF-8 -*- ...
#!/usr/bin/python # -*- coding: UTF-8 -*- tinydict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'} del tinydict['Name'] # 删除键是'Name'的条目 tinydict.clear() # 清空字典所有条目 del tinydict # 删除字典 print "tinydict['Age']: ", tinydict['Age'] print "tinydict[...
/usr/bin/python # -*- coding: UTF-8 -*- tinydict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'} tinydict['Age'] = 8 # 更新 tinydict['School'] = "RUNOOB" # 添加 print "tinydict['Age']: ", tinydict['Age']
#!/usr/bin/python # -*- coding: UTF-8 -*- dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'} del dict['Name'] # 删除键是'Name'的条目 dict.clear() # 清空字典所有条目 del dict # 删除字典 print "dict['Age']: ", dict['Age'] print "dict['School']: ", dict['Sch...