Script
#!/usr/local/bin/python3.4
dict = {}
dict['one'] = "This is one"
dict[2] = "This is two"
tinydict = {'Name': 'Kapil','Code':6789, 'Category': 'Allrounder'}
print(dict['one']) # Prints the value for 'one' key
print(dict[2]) # Prints the value for 2 key
print(tinydict) # Prints the complete dictionary
print(tinydict.keys()) # Prints the all the keys
print(tinydict.values()) # Prints the all the values
Execution
This is one
This is two
{'Category': 'Allrounder', 'Code': 6789, 'Name': 'Kapil'}
dict_keys(['Category', 'Code', 'Name'])
dict_values(['Allrounder', 6789, 'Kapil'])
#!/usr/local/bin/python3.4
dict = {}
dict['one'] = "This is one"
dict[2] = "This is two"
tinydict = {'Name': 'Kapil','Code':6789, 'Category': 'Allrounder'}
print(dict['one']) # Prints the value for 'one' key
print(dict[2]) # Prints the value for 2 key
print(tinydict) # Prints the complete dictionary
print(tinydict.keys()) # Prints the all the keys
print(tinydict.values()) # Prints the all the values
Execution
This is one
This is two
{'Category': 'Allrounder', 'Code': 6789, 'Name': 'Kapil'}
dict_keys(['Category', 'Code', 'Name'])
dict_values(['Allrounder', 6789, 'Kapil'])
No comments:
Post a Comment