字典 元组 集合的使用方法

字典,元组,集合的使用方法

字典增的使用方法

dictory = {‘猪’:‘pig’,‘狗’:‘dog’,‘狼’:‘holf’}
print(dictory)
dictory[‘鸟’] = ‘bird’
print(dictory)
dictory = {‘猪’:‘pig’,‘狗’:‘dog’,‘狼’:‘holf’}
print(dictory)
dictory[‘鸟’] = ‘bird’
print(dictory)
{‘猪’: ‘pig’, ‘狗’: ‘dog’, ‘狼’: ‘holf’}
{‘猪’: ‘pig’, ‘狗’: ‘dog’, ‘狼’: ‘holf’, ‘鸟’: ‘bird’}

添加多个元素

dictory = {‘鸟’:‘bird’,‘狗’:‘dog’,‘狼’:‘holf’}
print(dictory)
dictory[‘猪’] = ‘pig’
print(dictory)
dictory.update({‘蜜蜂’:‘bee’,‘猫’:‘cat’})
dictory = {‘鸟’:‘bird’,‘狗’:‘dog’,‘狼’:‘holf’}
print(dictory)
dictory[‘猪’] = ‘pig’
print(dictory)
dictory.update({‘蜜蜂’:‘bee’,‘猫’:‘cat’})
{‘鸟’: ‘bird’, ‘狗’: ‘dog’, ‘狼’: ‘holf’}
{‘鸟’: ‘bird’, ‘狗’: ‘dog’, ‘狼’: ‘holf’, ‘猪’: ‘pig’}

dictory = {‘我’:‘i’,‘爱’:‘love’,‘你’:‘you’}
print(dictory)
del dictory[‘你’]
print(dictory)
dictory = {‘我’:‘i’,‘爱’:‘love’,‘你’:‘you’}
print(dictory)
del dictory[‘你’]
print(dictory)
{‘我’: ‘i’, ‘爱’: ‘love’, ‘你’: ‘you’}
{‘我’: ‘i’, ‘爱’: ‘love’}

dictory = {‘鸟’:‘bird’,‘狗’:‘dog’,‘狼’:‘holf’}
dictory[“鸟”] = “you”
print(dictory)
{‘鸟’: ‘you’, ‘狗’: ‘dog’, ‘狼’: ‘holf’}

dictory = {‘我’:‘i’,‘爱’:‘love’,‘你’:‘you’}
prin
dictory = {‘我’:‘i’,‘爱’:‘love’,‘你’:‘you’}
print(dictory[‘我’])
print(dictory)
i
{‘我’: ‘i’, ‘爱’: ‘love’, ‘你’: ‘you’}

元组的使用方法

定义一个元组

t1 = ([1,2,3],4)
print(t1)
([1, 2, 3], 4)

增加元组

t1 = ([1,2,3],4)
t1[0].append(4)
print(t1)
([1, 2, 3, 4], 4)

删除(注:元组的删除是删除整组)

t10000=(1,2,3,4)
del t10000

查找按#查找

集合的使用方法

a={10,20,30,40,50}
print(a)
{40, 10, 50, 20, 30}

a.add(60)
print(a)
{40, 10, 50, 20, 60, 30}
a.update([70,90])
print(a)

a.pop()
print(a)
{10, 50, 20, 60, 30}

print(a)
{10, 50, 20, 60, 30}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值