Q:

Write a Python program to remove items 10, 20, 30 from the following set at once.

belongs to collection: Python Set Exercises

0

Remove items from the set at once

Write a Python program to remove items 10, 20, 30 from the following set at once.

Given:

set1 = {10, 20, 30, 40, 50}

Expected output:

{40, 50}

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Hint:

Use the difference_update() method of a set.

Solution:

set1 = {10, 20, 30, 40, 50}
set1.difference_update({10, 20, 30})
print(set1)

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Return a set of elements present in Set A or B, bu... >>
<< Given two Python sets, write a Python program to u...