Home >>Python Set Methods >Python Set pop() Method

Python Set pop() Method

Python Set pop() Method

Python Set pop() Method in python set is an inbuilt method which is used to removes a random element from the set and returns the popped (removed) elements.

Syntax:
set.pop()
Here is an example of Python Set pop() Method:

tech = {"java", "python", "mySql"}
tech.pop() 
print(tech)

Output:
{'java', 'mySql'}
Example 2:

tech1 = {"java", "php", "python", "mySql", "javaScript"} 
print(tech1.pop()) 
print(tech1.pop()) 
print(tech1.pop())  
print("Updated set ", tech1)

Output:
javascript
java
mySql
Updated set {'php', 'python'}

No Sidebar ads