Changes

Jump to: navigation, search

OPS435 Python Lab 4

39 bytes added, 16:54, 15 June 2017
PART 3 - Dictionaries
::#Let's begin by creating a new dictionary (for practice):<source>
dict_york = {'Address': '70 The Pond Rd', 'City': 'Toronto', 'Postal Code': 'M3J3M6'}
</source>You should note that the syntax to define a dictionary is similar to defining sets (i.e. using '''{}''').<br>Unlike sets, dictionaries use '''<code>key:value</code>''' pairs within the dictionary, each ''key:value'' pair in turn, are separated by commas.<br><br>You can get help associated with your dictionary by using functions such as '''dir()''' and '''help()'''.<br><br>
::#Issue the following and note all the available functions available and how to obtain assistance with dictionary objects:<source>
dir(dict_york)
help(dict_york.values)
dict_york.values()
</source>All keys (to access a dictionary) can be viewed by using the '''dictionary.keys() ''' function. This function provides a '''list''' containing all keys<br><br>
::#To demonstrate this fact, issue the following:<source>
help(dict_york.keys)
13,420
edits

Navigation menu