![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can I remove items out of a Python tuple?
Tuples in python are immutable. If you want to remove items out of a Python tuple, you can use index slicing to leave out a particular index. For example,
a = (1, 2, 3, 4, 5) b = a[:2] + a[3:] print(b)
This will give the output:
(1, 2, 4, 5)
Or you can convert it to a list, remove the item and convert back to a tuple. For example,
a = (1, 2, 3, 4, 5) ls_a = list(a) del ls_a[2] b = tuple(ls_a) print(b)
This will give the output:
(1, 2, 4, 5)
Advertisements