beginnersbook.com

  • Home
  • All Tutorials
    • Learn Servlet
    • Learn JSP
    • Learn JSTL
    • Learn C
    • Learn C++
    • Learn MongoDB
    • Learn XML
    • Learn Python
    • Learn Perl
    • Learn Kotlin
  • Core Java
  • OOPs
  • Collections
  • Java I/O
  • JSON
  • DBMS

Python Set pop() method with examples

By Chaitanya Singh | Filed Under: Python Tutorial

The pop() method in Python removes a random element from a given set and returns the removed element.

Set pop() method Syntax

set.pop()

Parameter: This method doesn’t take any parameter.
Return Value: It returns the removed element of the Set.

If you call this method on an empty set then an error is raised.

Python Set pop() method Example

In the following example we have a Set X and we are calling pop() method on this set. The pop() method removes a random element from the set and returns the removed element.

# My Set
X ={"hello", 2, 10, 99, "hi"}

# Displaying Set before calling pop()
print("Original Set is:",X)

# Calling pop() method
print("Removed element:",X.pop())

# Displaying Set after calling pop()
print("Set after pop():", X)

Output:
Python pop() method example

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Python Tutorial

Introduction

  • Python Tutorial
  • Python Introduction
  • Install Python
  • PyCharm IDE Installation
  • Python in PyCharm
  • Python Comments
  • Python Variables
  • Python Keywords & Identifiers
  • Python data types

Flow Control

  • Python If
  • Python if..else
  • Python if..elif..else
  • Python Nested If
  • Python for loop
  • Python while loop
  • Python break
  • Python continue
  • Python pass

Python Functions

  • Python Functions
  • Python Recursion

Python Datatypes

  • Python Numbers
  • Python List
  • Python Strings
  • Python Tuple
  • Python Dictionary
  • Python Set

Python OOPs

  • Python OOP
  • Python Class & Object
  • Python Constructors

Python Examples

  • Python Programs

Recently Added..

  • JSON Tutorial
  • Java Regular Expressions Tutorial
  • Java Enum Tutorial
  • Java Annotations Tutorial

Copyright © 2012 – 2021 BeginnersBook . Privacy Policy . Sitemap