Rt, small white for help is how to extract a particular key name of the key/value pair
CodePudding user response:
KEY in the dictionary is a unique, specific KEY name refers to what?
CodePudding user response:
li=[1, 3, 4, 5, 6, 6, 5, 4]
Dict_a={
"Zhang SAN" : 'male',
"Bill" : 'female',
"Two" : 'confidential'
}
Dict_li={
'a' : 1,
'b' : 'hello',
'c' : li,
'd' : {" ABC ", 123, "hello", 123, 'ABC'},
'e' : dict_a,
'f' : {30, "bill" : "* *" : 20, "two" : 18,}
}
Print (dict_li [' a '])
Print (dict_li [' b '])
Print (dict_li [' c '])
Print (dict_li [' c '] [2])
Print (dict_li [' d '])
Print (dict_li [' e '])
Print (dict_li [' e '] [' zhang '])
Print (dict_li [' f '])
Print (dict_li [' f '] [' zhang '])
Output:
1
Hello
[1, 3, 4, 5, 6, 6, 5, 4]
4
{' ABC '123,' hello '}
{' ABC '123,' hello '}
{' zhang ':' male ', 'bill' : 'female' and 'two' : 'confidential'}
Male
{' bill ': 30,' zhang SAN: 20, 'the king 2:18}
20
CodePudding user response:
dict1={1: 'Joe', 2: "bill"}
Print (dict1 [1])
For the key and the value in dict1. The items () :
Print (key, value)
For the key in dict1. Keys () :
Print (dict1 [key])
CodePudding user response: