
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Delete Tuple Elements in Python
Removing individual tuple elements is not possible. There is, of course, nothing wrong with putting together another tuple with the undesired elements discarded.
To explicitly remove an entire tuple, just use the del statement.
Example
#!/usr/bin/python tup = ('physics', 'chemistry', 1997, 2000); print tup; del tup; print "After deleting tup : "; print tup;
Output
This produces the following result. Note an exception raised, this is because after del tup tuple does not exist any more −
('physics', 'chemistry', 1997, 2000) After deleting tup : Traceback (most recent call last): File "test.py", line 9, in <module> print tup; NameError: name 'tup' is not defined
- Related Articles
- Delete List Elements in Python
- Delete Dictionary Elements in Python
- Delete elements in range in Python
- Modulo of tuple elements in Python
- Python - Join tuple elements in a list
- How to append elements in Python tuple?
- Python – Concatenate Rear elements in Tuple List
- Finding unique elements from Tuple in Python
- Raise elements of tuple as power to another tuple in Python
- Count the elements till first tuple in Python
- Python Program to Replace Elements in a Tuple
- Delete elements with frequency atmost K in Python
- Python – Filter tuple with all same elements
- Maximum and Minimum K elements in Tuple using Python
- How to get unique elements in nested tuple in Python

Advertisements