It is a method in python set that removes the specified element from the current set. If it doesn’t exist then it throws a KeyError Exception. It doesn’t return any value and modifies the given set.
Syntax:
set.remove(element)
Also Read: Python Set – add() method
Example 1:
# Python code to understand remove() method in set
# www.codewindow.in
s = {"amazing", "code", "best"}
s.remove("code")
print(s)
Output:
{'amazing', 'best'}
Explanation:
Here the element “code” has been removed from the parent set (s).
Example 2:
# Python code to understand remove() method in set
# www.codewindow.in
s = {5, 8, 4, 1, 5, 9}
s.remove(5)
print(s)
Output:
{1, 4, 8, 9}
Explanation:
Here the element “5” has been removed from the parent set (s).
Note: set doesnt allow duplicate element.
Example 3:
# Python code to understand remove() method in set
# www.codewindow.in
s = {5, 8, 4, 1, 5, 9}
s.remove(6)
print(s)
Output:
Traceback (most recent call last):
File "./prog.py", line 2, in
KeyError: 6
Explanation:
Here it throws an exception since the element is not present on the set. For this we use the method discard() which doesn’t throws an exception.
Follow Us
You Missed
- Software Engineering – codewindow.in
- Software Engineering – codewindow.in
- Software Engineering – codewindow.in
- Software Engineering – codewindow.in
- Software Engineering – codewindow.in
- MongoDB – codewindow.in
- MongoDB – codewindow.in
- MongoDB – codewindow.in
- Software Engineering – codewindow.in
- Software Engineering – codewindow.in
- Software Engineering – codewindow.in
- Software Engineering – codewindow.in
- PHP & MySQL – codewindow.in
- PHP & MySQL – codewindow.in
- PHP & MySQL – codewindow.in
- Certificates
- PHP & MySQL – codewindow.in
- PHP & MySQL – codewindow.in
- PHP & MySQL – codewindow.in
- CSS – codewindow.in
- CSS – codewindow.in
- CSS – codewindow.in
- Database Management System – codewindow.in
- Database Management System – codewindow.in
- JQuery – codewindow.in
- JQuery – codewindow.in
- MongoDB – codewindow.in
- MongoDB – codewindow.in
- MongoDB – codewindow.in
- Database Management System – codewindow.in
- MongoDB – codewindow.in
- MongoDB – codewindow.in
Also Checkout
- Adobe
- Ajax
- Algorithm
- Amagi
- Amazon Interview Questions
- Angular JS
- Aptitude
- big data
- Books
- Bridge2i
- C programming
- Campgemini Interview Questions
- Capgemini Coding Questions
- Capgemini Pseudocode
- Celebal Tech
- Cloud Computing
- code nation
- CodeVita
- Coding Questions
- Cognizant Placement
- commvault Systems
- Computer Network
- CSS
- CTS
- Data Science
- Data Structure and Algorithm
- Database Management System
- De Show Interview Questions
- deloitte
- Deutsche Bank Interview questions
- Epam Full Question Paper
- Exxon Mobil interview questions
- filpkart
- Fractal Analytics Interview Questions
- Genpact
- Grab
- GreyB Interview Questions
- Guidance for Accenture
- Gupshup
- HCL Interview Questions
- Hexaware
- HFCL
- HR Questions
- HTML5
- IBM Interview questions
- IBM Questions
- Incture Interview Questions
- Infineon Technologies Interview Questions
- Infosys
- Infosys Interview Questions
- Internship
- Interview Experience
- Interview Questions
- ITC Infotech
- itron
- JavaScript
- JECA
- Job Info
- JQuery
- Kantar Interview Questions
- Larsen & Turbo
- Latenview AnalyticsInterview questions
- Lexmark International Interview Questions
- Machine Learning
- Media.net
- Mindtree Interview Questions
- Miscellaneous
- MongoDB
- Morgan Stanly Interview Questions
- nagarro
- navi
- NodeJS
- NPCI
- NTT Data Interview Questions
- NVDIA
- NVDIA interview questions
- Optum
- PayU
- Persistent INterview Questions
- PHP and MYSQL
- Programming in C
- Programming in C++
- Programming in JAVA
- Programming in Python
- Project
- pseudocode
- PWC Interview Questions
- Python
- Quiz
- Razorpay
- ReactJS
- Recruiting Companies
- Revature
- salesforce
- Samsung
- Schlumberger
- Seimens
- Slice
- Smart Cube
- Software Engineering
- Study Material
- Tally Solutions
- tata cliq
- TCS
- TCS NQT
- TCS NQT Coding Questions
- Tech Mahindra Coding Questions
- Tech Mahindra Questions
- Teg Analytics
- Tejas Network Interview Questions
- Texas Instrument Interview Questions
- Tiger Analytics
- Uncategorized
- UnDosTres
- Unstop
- Verbal Ability
- Web Development
- Wipro Coding Questions
- Wipro interview Questions
- Wipro NLTH
- WIpro NLTH Coding Solve
- Zenser
- Zoho Interview Questions