dictionary syntax in python code example
Example 1: dictionary in python
programming_dictionary = {
"Bug": "An error in a program that prevents the program from running as expected.",
"Function": "A piece of code that you can easily call over and over again.",
"Loop": "The action of doing sommething again and again",
}
print(programming_dictionary["Function"])
for key in programming_dictionary:
print(programming_dictionary[key])
programming_dictionary["Variable"] = "The label to store some sort of data"
print(programming_dictionary["Variable"])
programming_dictionary["Variable"] = "Variables are nothing but reserved memory locations to store values. This means that when you create a variableyou reserve some space in memory"
Example 2: dictionary in python
tel = {'jack': 4098, 'sape': 4139}
tel['guido'] = 4127
print(tel)
print(tel['jack'])
del tel['sape']
tel['irv'] = 4127
print(tel)
print(list(tel))
print(sorted(tel))
print('guido' in tel)
print('jack' not in tel)
Example 3: how to use dictionaries in python
student_data = {
"name":"inderpaal",
"age":21,
"course":['Bsc', 'Computer Science']
}
print(student_data['name'])
print(student_data['age'])
print(student_data['course'])[0]
Example 4: python dictionary
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
thisdict["year"] = 2018
Example 5: dictionary in python
d = {'key1':'value1','key2':'value2'}
print(d)
l=d.keys
print(l)
b=d.values
print(b)
Example 6: dictionary in python
thisdictionary = {'key':'value','key1':'value1'}
print(thisdictionary['key'])