Chapter 9 Key Terms Flashcards
Dictionary
Object that stores a collection of data.
key
Identifier for a value. They are used to access, modify, or add values.
value
The data associated with or within a key, are typically numbers, lists, strings, and can even be other dictionaries.
Syntax for Creating a Dictionary
dictionary =
{key1:val1, key2:val2}
Syntax for Retrieving a Value from a Dictionary
dictionary[key]
in
Is used to check if a key exists in a dictionary.
not in
Is used to check if a key does not exist in a dictionary.
Syntax for Adding Elements in a Dictionary
dictionary[key] = value
del
Is used to remove an element.
len
Is used to obtain a number of elements.
Data Types in a Dictionary
Data types such as integers, strings, lists, other dictionaries, etc.
Syntax for Creating an Empty Dictionary
empty_dict = {}
clear
Is used to remove all items from a dictionary.
get
Gets a value associated with a specified key.
items
Returns all the dictionary keys and associated values.
keys
Returns all the dictionary keys as a sequence.