How to Access Values
If you want to access the value of a key, you have to include the dictionary
name before placing the key in square brackets.
team1 ={‘color’: ‘red’, ‘scores’ : 3}
print(team1[‘color’])
The output for this code will return the corresponding key value from the
dictionary “team1,” which in this situation is red.
Python allows us to have an unlimited number of key-value pairs. We can
add more codes to illustrate this. Additionally, we can decide the particular
key-pair to print or display on the screen. In this code, it will display
‘London’
team1 ={‘color’: ‘red’, ‘scores’ : 3, ‘S/N’ : 1, ‘place’ : ‘London’}
print(team1[‘place’])
London
Do'stlaringiz bilan baham: |