Repository navigation
Expand file tree
/
Copy path071-Delete-Tuple.py
More file actions
61 lines (49 loc) · 2 KB
/
Copy path071-Delete-Tuple.py
File metadata and controls
61 lines (49 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""
===============================================================================
File Name : 71-Delete-Tuple.py
Description : Delete a Tuple in Python
Author : Shaik Mahaboob Basha
===============================================================================
Definition:
The del keyword is used to delete an entire tuple from memory. After deleting
the tuple, it can no longer be accessed.
Syntax:
del tuple_name
Example:
del numbers
"""
# -----------------------------------------------------------------------------
# Creating a tuple of integers.
# -----------------------------------------------------------------------------
numbers = (10, 20, 30, 40, 50)
# -----------------------------------------------------------------------------
# Displaying the original tuple.
# -----------------------------------------------------------------------------
print("Original Tuple :", numbers)
# Output:
# Original Tuple : (10, 20, 30, 40, 50)
print()
# -----------------------------------------------------------------------------
# Displaying the total number of elements in the tuple.
# -----------------------------------------------------------------------------
print("Total Elements :", len(numbers))
# Output:
# Total Elements : 5
print()
# -----------------------------------------------------------------------------
# Deleting the entire tuple.
# -----------------------------------------------------------------------------
del numbers
# -----------------------------------------------------------------------------
# Displaying a confirmation message.
# -----------------------------------------------------------------------------
print("The tuple has been deleted successfully.")
# Output:
# The tuple has been deleted successfully.
print()
# -----------------------------------------------------------------------------
# Attempting to access the deleted tuple.
# -----------------------------------------------------------------------------
print(numbers)
# Output:
# NameError: name 'numbers' is not defined