python笔记:1.3.3字典操作

博客展示了包含个人信息、城市信息等内容。有姓名为老王,21岁男性的信息,还有长春的人口、面积、位置、天气等信息,同时还展示了数字5、布尔值True和False。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

# -*- coding: utf-8 -*-
"""
Created on Tue May  7 14:34:41 2019

@author: Administrator
"""

d={'name':'老王', 'Gender':'男', '年龄':'21', '身高':'181'}
print(d)

item1 = [('city','长春'), ('renkou','500'), ('area','23'), ('posi','north'), ('weather','sunny')]
d1 = dict(item1)
print(d1)

print(len(d1))

#返回关联到某键的值
print(d1['city'])

#删除某键
del d1['renkou']
print(d1)

# 查找键
print('city' in d1)
print('aa' in d1)

运行:

{'name': '老王', 'Gender': '男', '年龄': '21', '身高': '181'}
{'city': '长春', 'renkou': '500', 'area': '23', 'posi': 'north', 'weather': 'sunny'}
5
长春
{'city': '长春', 'area': '23', 'posi': 'north', 'weather': 'sunny'}
True
False

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值