Are Python sets mutable

0 votes
x = set([11, 12, 13])
y = x

y |= set([14, 15, 16])

Are x and y still pointing to the same object, or was a new set created and assigned to y?

Feb 17 in Python by Nandini
• 5,480 points
33 views

1 answer to this question.

0 votes

Python sets are data structures which are used to store values.
Sets are unique in the sense that they will not hold duplicate values, also sets are unordered.
There are frozen class of sets which are immutable and also a class exists where sets can be changed.

An Example:

x = set([1, 2, 3])
y = x
y |= set([4, 5, 6])
y

Output

{1, 2, 3, 4, 5, 6}
x

Output

{1, 2, 3, 4, 5, 6}

Both x and y are set and are same.

answered Feb 17 by Dev
• 6,000 points

Related Questions In Python

0 votes
1 answer

Are Python sets mutable?

>>>> x = set([4, 5, 6]) Sets are ...READ MORE

answered Feb 18 in Python by CoolCoder
• 4,360 points
67 views
0 votes
1 answer

What are frozen sets in python?

A frozen set in Python is a ...READ MORE

answered Jun 11, 2019 in Python by Nisa
• 1,090 points
1,119 views
0 votes
1 answer

what are "and" and "or" operators in Python?

AND - True if both the operands ...READ MORE

answered Apr 18, 2018 in Python by Johnathon
• 9,090 points
257 views
0 votes
2 answers

What are the types of dictionary in python?

There are 4 types of dictionary Empty Integer Mixed Dictionary with ...READ MORE

answered Feb 14, 2019 in Python by Shashank
• 1,370 points
269 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 2,821 views
0 votes
1 answer
0 votes
1 answer
0 votes
2 answers

What's the difference between %s and %d in Python string formatting?

The reason is that they are using ...READ MORE

answered Feb 8 in Python by Rahul
• 8,980 points
32 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP