Advertisements
Advertisements
प्रश्न
When to use a tuple or dictionary in Python. Give some examples of programming situations mentioning their usefulness.
टीपा लिहा
Advertisements
उत्तर
Tuples are used to store the data which is not intended to change during the course of the execution of the program. For example, if the name of months is needed in a program, then the same can be stored in the tuple as generally, the names will either be iterated for a loop or referenced sometimes during the execution of the program.
Dictionary is used to store associative data like the student's roll no. and the student's name. Here, roll no. will act as a key to find the corresponding student's name. The position of the data doesn’t matter as the data can easily be searched by using the corresponding key.
shaalaa.com
Concepts of Tuples in Python
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
