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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly