Repository navigation
Expand file tree
/
Copy path064-Delete-List.py
More file actions
61 lines (49 loc) · 1.98 KB
/
Copy path064-Delete-List.py
File metadata and controls
61 lines (49 loc) · 1.98 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 : 64-Delete-List.py
Description : Delete a List in Python
Author : Shaik Mahaboob Basha
===============================================================================
Definition:
The del keyword is used to delete an entire list from memory. After deleting
the list, it can no longer be accessed.
Syntax:
del list_name
Example:
del numbers
"""
# -----------------------------------------------------------------------------
# Creating a list of integers.
# -----------------------------------------------------------------------------
numbers = [10, 20, 30, 40, 50]
# -----------------------------------------------------------------------------
# Displaying the original list.
# -----------------------------------------------------------------------------
print("Original List :", numbers)
# Output:
# Original List : [10, 20, 30, 40, 50]
print()
# -----------------------------------------------------------------------------
# Displaying the number of elements in the list.
# -----------------------------------------------------------------------------
print("Total Elements :", len(numbers))
# Output:
# Total Elements : 5
print()
# -----------------------------------------------------------------------------
# Deleting the entire list.
# -----------------------------------------------------------------------------
del numbers
# -----------------------------------------------------------------------------
# Displaying a confirmation message.
# -----------------------------------------------------------------------------
print("The list has been deleted successfully.")
# Output:
# The list has been deleted successfully.
print()
# -----------------------------------------------------------------------------
# Attempting to access the deleted list.
# -----------------------------------------------------------------------------
print(numbers)
# Output:
# NameError: name 'numbers' is not defined