Dictionary
Python dictionary is an unordered collection of items. In dictionary, each item has a key/value pair.
Example:users = {'name':'Junaid', 'age':25}
print(users)
print(type(users))
# access data from dictionaries
print(users['name'])
user_info = {
'name' : 'Junaid Shaikh',
'age' : 24,
'skills' : ['a', 'v'],
'tunes' : ['t', 'tv'],
}
print(user_info['skills'])
Function | Description |
---|---|
dict.clear() | removes all elements of dictionary dict |
dict.copy() | returns a shallow copy of dictionary dict |
dict.items() | retuns a list of dict's (key, value) tuple pairs |
dict.setdeafult(key, default=Nonre) | similiar to get(), but will set dict[key] = default |
dict.update(dict2) | adds dictionary dict2's key-values pairs to dict |
dict.keys() | returns list of dictionary dict's keys |
dict.values() | returns list of dictionary dict's values |