| You are here: | About>Computing & Technology>Python |
![]() | Python |
Beginning Python: Data TypesDictionariesDefining a DictionaryDictionary is the Python term for an associative array. An array is, like a list, a series of values in two dimensions. An associative array gives one a way of accessing the values by a key, a term associated with the value instead of an item's index number. Initializing a dictionary, one offsets the keys and values in curly braces. Each key-value pair is separated from the others by a comma. For each pair, the key and value are separated by a colon. The key of each member is offset in quotes. A sample dictionary is as follows: my_dictionary = { "author" : "Andrew Melville", Accessing a DictionaryOne accesses a dictionary member by its key: >>> a = my_dictionary["author"] To insert or modify a member, one simply assigns the value: >>> my_dictionary["publisher"] = 'Harper and Brothers'
<< Previous | Next |
Las Vegas on a BudgetFind a BargainHotel DealsCheap EatsFree AttractionsEntertainment for Less |
All Topics | Email Article | Print this Page | | ![]() |
| Advertising Info | News & Events | Work at About | SiteMap | Reprints | Help | Our Story | Be a Guide |
| User Agreement | Ethics Policy | Patent Info. | Privacy Policy | ©2008 About, Inc., A part of The New York Times Company. All rights reserved. |


