dictionary methods Flashcards

(4 cards)

1
Q

are dictionaries indexable?

A

yes, indexed by keys rather than numerical position

you can ‘look things up’

indices of dictionaries are keys of arbitrary value

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

method that takes a key as an argument and returns the value associated with it

if the key doesn’t exist it will return none

A

.get()

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

takes a key as an argument and returns the value but also deleting the kay-value pair

A

.pop()

mutating method

returns KeyError is key isn’t in the dictionary

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

deletes the entire contents

A

.clear()

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