Python Set remove() MethodPython remove() method removes an element elem from the set. It raises error KeyError if elem is not contained in the set. See the examples given below. SignatureParameterselem: element to be deleted. ReturnIt returns None but throws KeyError if the value does not found in the set. Let's see some examples of remove() method to understand it's functionality. Python Set remove() Method Example 1Let's first see a simple example to remove an element from the set. Output: {1, 2, 3} After removing element: {2, 3} Python Set remove() Method Example 2It throws an error KeyError if the element is not available in the set. See the example. Output: set.remove(22) KeyError: 22 Python Set remove() Method Example 3This method can be easily implemented into program to perform some business logic. See an examplpe below. Output: {'a', 'c', 'i', 't', 'n', 'u', 'y', 's', 'd', 'o', 'r'} {'a', 'i', 'u', 'o'}
Next TopicPython Set
|
JavaTpoint offers too many high quality services. Mail us on [email protected], to get more information about given services.
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected]
Duration: 1 week to 2 week