Ai
5 Star 28 Fork 15

极客挖掘机/python-learning

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Demo.py 698 Bytes
一键复制 编辑 原始数据 按行查看 历史
dict1 = {'name': 'geekdigging', 'age': 2}
print(dict1)
print(type(dict1))
dict2 = {(1, 2, 3): '123', 'name': 'geekdigging', 2: [1, 2, 3]}
print(dict2)
print(type(dict2))
dict3 = dict(name = 'geekdigging', age = 2)
print(dict3)
print(type(dict3))
# 语法错误,注释
# dict4 = dict(1 = 'geekdigging', 2 = 2)
print(dict1['name'])
# 键不存在示例,报错 KeyError
# print(dict1['geekdigging'])
str = 'geekdigging'
if str in dict1:
print(dict1['geekdigging'])
else:
print('您查询的键', str, '不存在')
# 添加
dict1['a'] = 18
print(dict1)
# 更新
dict1['name'] = 'www.geekdigging.com'
print(dict1)
# 删除
del dict1['a']
print(dict1)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/inwsy/python-learning.git
git@gitee.com:inwsy/python-learning.git
inwsy
python-learning
python-learning
master

搜索帮助