4 Respuestas
+ 2
Simply, dictionary is a way to store the data in pairs of keys and values and we can access any value by using key name as index.
They are enclosed in curly braces {}.
For example (by Wong Hei Ming):-
dic = {'apple': 1.99, 'orange': 2.49, 'bananas': 2.99}
Here dic is dictionary, always keep remember that key and value pairs are represent by colony(:) and we use comma(,) to separate different pairs as I did in above example.
As I already said we use key name as index to access the value.
Wong Hei Ming already gave you an example of how to extract a particular value from a dictionary.
Also you can have multiple values for a specific key or you can say a list of several values.For example:-
dic = {'fruits': ['apple','orange','bananas'], 'animals': ['dog', 'cat', 'tiger']}
Also there are several methods you can perform on dictionary.
Try review the lesson again and practice in python tab available in Sololearn.
Or you can use another sources too.So, you can better understand them.
+ 2
Some related threads:-
https://www.sololearn.com/discuss/2298115/?ref=app
https://www.sololearn.com/discuss/547691/?ref=app
https://www.sololearn.com/discuss/929417/?ref=app
https://www.sololearn.com/discuss/1558620/?ref=app
https://www.sololearn.com/discuss/3036787/?ref=app
https://www.sololearn.com/discuss/1858225/?ref=app
Some resources I found on Google:-
https://www.w3schools.com/JUMP_LINK__&&__python__&&__JUMP_LINK/python_dictionaries.asp
https://www.geeksforgeeks.org/python-dictionary/
https://www.simplilearn.com/dictionary-in-python-article
+ 1
Python dictionary is like, a dictionary.
Imagine you are a storekeeper, and you want a program to tell you how much is the item selling price.
In this case, you can create a dict, let's name it products.
products = dict()
And then we add some items.
products['apple'] = 1.99
products['orange'] = 2.49
products['banana'] = 2.99
Now you want to know the selling price of 'apple', you can do this.
print(products['apple'])
# it prints 1.99
0
adding to what Gulshan Mahawar said, you can also do,
dic = {
'apple': 1.99,
'orange': 2.49,
'bananas': 2.99
}
( by Wong Hei Ming )