您的位置:首页 > 编程语言 > Python开发

The study dict and set in Python(20170906)

2017-09-06 20:58 483 查看
In this part, the immutable object(不可变对象) is important. That means the object cann’t be modify in any time. Only can change the direction of object.

the dice(dictionary) and set inP Python

example dict

‘key’:value

information = {‘yuhanyu’:7,’guilin’:6,’man’:3}

print(information[‘yuhanyu’])

modify the value of some key

information[‘man’] = 4

print(information[‘man’])

delethe some key-value

information.pop(‘man’)

print(information)

the dict of key is a immutable object(不可变对象 )

example set

num = set([5,6,7])

print(num)

set([the is a list])

the set will delete repeat element

num2 = set([5,5,6,6,7,7])

print(num2)

the add(element) function can increase a element to set

num2.add(8)

print(num2)

the remove(element) function can delete a elemnet in set

num2.remove(5)

print(num2)

the among of sets have intersection(交集) and union

print(num & num2)

print(num | num2)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: