Dictionaries and Tuples Flashcards
1
Q
*
What is the main difference between lists and tuples in Python?
A
Lists: Lists are mutable, which means you can change their content after creation. You can add, remove, or modify elements in a list.
Tuples: Tuples are immutable, which means once you create a tuple, you cannot change its content. You cannot add, remove, or modify elements in a tuple.
2
Q
What are differences between dictionaries and lists?
A
- Dictionaries allow for a mapping between keys and values, whereas lists only map indices to values.
- Dictionaries have an unchangeable part(keys must be unchangeable), while lists are completely changeable
3
Q
how to add a new key-value par in a dic in python?
A
my_dict[‘city’] = ‘New York’ # Adding a new key-value pair