The study dict and set in Python(20170906)

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)

你可能感兴趣的:(python)