0

Python Dictonary

There are not clearly define python Dictonary so please add somone proper examples and usage of dictonary in python

29th Dec 2024, 7:06 AM
Fazlirahman Jaan
Fazlirahman Jaan - avatar
4 Antworten
+ 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.
29th Dec 2024, 10:49 AM
Gulshan Mahawar
Gulshan Mahawar - avatar
+ 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
29th Dec 2024, 7:51 AM
Wong Hei Ming
Wong Hei Ming - avatar
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 )
30th Dec 2024, 1:37 AM
cedrick2013
cedrick2013 - avatar