# Python Set pop() Method with Example

**Python Set pop() Method**: Here, we are going to learn how to remove an element from the set in Python?

Submitted by **IncludeHelp**, on November 30, 2019

## Set pop() Method

**pop() method** is used to remove a random element from the set, the method is called with this set and remove a random element from the set.

**Syntax:**

set_name.pop()

**Parameter(s):**

- It does not accept any parameter.

**Return value:**

The return type of this method is the type of the element, it returns the removed/popped element.

**Example:**

# Python Set pop() Method with Example # declaring the sets cars = {"Porsche", "Audi", "Lexus", "Mazda", "Lincoln"} nums = {100, 200, 300, 400, 500} # printing the sets before removing print("Before the calling pop() method...") print("cars: ", cars) print("nums: ", nums) # Removing/popping the elements from the sets x = cars.pop() print(x, "is removed from cars") x = cars.pop() print(x, "is removed from cars") x = cars.pop() print(x, "is removed from cars") x = nums.pop() print(x, "is removed from nums") x = nums.pop() print(x, "is removed from nums") x = nums.pop() print(x, "is removed from nums") # printing the sets after removing print("After the calling pop() method...") print("cars: ", cars) print("nums: ", nums)

**Output**

Before the calling pop() method... cars: {'Audi', 'Porsche', 'Lexus', 'Mazda', 'Lincoln'} nums: {100, 200, 300, 400, 500} Audi is removed from cars Porsche is removed from cars Lexus is removed from cars 100 is removed from nums 200 is removed from nums 300 is removed from nums After the calling pop() method... cars: {'Mazda', 'Lincoln'} nums: {400, 500}

TOP Interview Coding Problems/Challenges

- Run-length encoding (find/print frequency of letters in a string)
- Sort an array of 0's, 1's and 2's in linear time complexity
- Checking Anagrams (check whether two string is anagrams or not)
- Relative sorting algorithm
- Finding subarray with given sum
- Find the level in a binary tree with given sum K
- Check whether a Binary Tree is BST (Binary Search Tree) or not
- 1[0]1 Pattern Count
- Capitalize first and last letter of each word in a line
- Print vertical sum of a binary tree
- Print Boundary Sum of a Binary Tree
- Reverse a single linked list
- Greedy Strategy to solve major algorithm problems
- Job sequencing problem
- Root to leaf Path Sum
- Exit Point in a Matrix
- Find length of loop in a linked list
- Toppers of Class
- Print All Nodes that don't have Sibling
- Transform to Sum Tree
- Shortest Source to Destination Path

Comments and Discussions

**Ad:**
Are you a blogger? Join our Blogging forum.