What are tuples and dictionaries in Python?
Answers
A tuple is a data structure that is an immutable, or unchangeable, ordered sequence of elements. Because tuples are immutable, their values cannot be modified.
A Python dictionary is a mapping of unique keys to values. Dictionaries are mutable, which means they can be changed. The values that the keys point to can be any Python value.
HOPE HELPED:)
THAT'S ANANYA ✌✌
Hi,
What is Tuple?
Tuple is list of immutable objects. Means we can't change them, but their values may change.
syntax:
tuple_of_names = ('Ajay', 'Nitiz', 'Pankaj);
we can fetch the friend using following syntax
tuple_of_names[0]
What are dictionaries in Python?
In Python Dictionaries are just like associative array of php. Actually they are just like tuples but if w have to access the value of dictionary then we use key instead of index, but we can mutate it.
We can make a dictionary with the help of dict() constructor
syntax
this_is_dict = dict(friendOne="Ajay", friendTwo="Nitiz", friendThree="Pankaj");
we can fetch particular friend by using following syntax:
suppose we want to fetch Nitiz, syntax will be
print(this_is_dict ["friendTwo"]);
So main difference is:
1.) Tuples are index based but dictionaries are key based
2.) Tuples are immutable whereas Dictionaries are mutable.