Python Set Methods Flashcards

1
Q

set()

A

creates an empty set.

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

add()

A

Adds an element to the set.

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

remove()

A

Removes a specified element from the set. Raises keyError if not found.

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

discard()

A

removes a specific element from the set(does nothing if nothing found)

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

pop()

A

Removes and returns a random element from the set

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

union()

A

Returns a new set by combining both sets

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

intersection()

A

Returns a new set with elements common to both sets.

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

difference()

A

Returns a new set with elements in the first set but not in the second set.

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

symmetric-difference()

A

Returns a new set with elements in either set but not in both.

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

len()

A

checking length

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

in/ not in

A

Checking if element is in the set

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

copy()

A

Returns a shallow copy of the set

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

clear()

A

Removes all elements from the set.

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