Important Notice:

Course Content
Set Data Type in Python (Chapter-14) M3-R5
About Lesson

1.       a={10,20,30}

a.add(50)

print(a)

Output

{10, 20, 50, 30}

a={10,20,30}

a.add((10,20))

print(a)

Output

{10, 20, 30, (10, 20)}

2. a={10,20,30}

    a.clear()

    print(a)

Output

set()

3. a={10,20,30}

b=a.copy()

print(a)

print(b)

Output

{10, 20, 30}

{10, 20, 30}

4. a={10,20,30}

b={10,30,60}

print(a.difference(b))

Output

{20}

5. a={10,20,30}

a.discard(10)

print(a)

Output

{20, 30}

6. a={10,20,30}

b={10,30,60}

print(a.intersection(b))

Output

{10, 30}

7. a={10,30}

b={10,30,60}

print(a.issubset(b))

Output

True

8. a={10,30}

b={10,30,60}

print(b.issuperset(a))

Output

True

9. a={10,20,30,40,50}

b=a.pop()

print(a)

print(b)

Output

{20, 40, 10, 30}

10. a={10,20,30,40,50}

a.remove(10)

print(a)

Output

{50, 20, 40, 30}

11. x={10,20,30}

y={40,50,60}

z=x.union(y)

print(z)

Output

{50, 20, 40, 10, 60, 30}

12. a={10,20,30}

a.update([50])

print(a)

Output

{10, 20, 50, 30}

a={10,20,30}

a.update((40,50,60))

print(a)

Output

{40, 10, 50, 20, 60, 30}

a={10,20,30}

a.update(50)

print(a)

Output

TypeError: ‘int’ object is not iterable

error: Content is protected !!