- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Program to remove items from set
We are very much familiar with the term set because in the point of mathematics, we know about set. Set in Python is a data structure equivalent to sets in mathematics. It may consist of various elements; the order of elements in a set is undefined. You can add and delete elements of a set, you can iterate the elements of the set, and you can perform standard operations on sets (union, intersection, difference).
Here set is given we just remove element from the set. here we use pop() method, The pop() is an inbuilt method in Python that is used to pop out or remove the elements one by one from the set.
Example
A = [2, 9, 80, 115, 22, 120] Output NEW SET IS ::> {9, 80, 115, 22, 120} {80, 115, 22, 120} {115, 22, 120} {22, 120} {120} Set ()
Algorithm
Step 1: Create a set. Step 2: Use pop() function. The method pop() removes and returns last object from the list.
Example Code
# Python program to remove elements from set def removeelement(set1): print("NEW SET IS ::>") while set1: set1.pop() print(set1) # Driver Code set1 = set([22, 120, 130, 115, 80, 9]) removeelement(set1)
Output
NEW SET IS ::> {9, 80, 115, 22, 120} {80, 115, 22, 120} {115, 22, 120} {22, 120} {120} set()
- Related Articles
- Python Program to remove items from the set
- Java program to remove items from Set
- C++ Program to remove items from a given vector
- C# program to remove an item from Set
- Swift Program to Remove an Element from the Set
- How do you remove multiple items from a list in Python?
- Java Program to remove all elements from a set in Java
- How to remove items from a list in C#?
- Python program to remove Duplicates elements from a List?
- Python Program to Remove Palindromic Elements from a List
- How to dynamically remove items from ListView on a click?
- Remove duplicate items from an ArrayList in Java
- Python program to remove leading zeros from an IP address
- Python program to remove all duplicates word from a given sentence.
- Python program to remove duplicate elements from a Doubly Linked List

Advertisements