Repository navigation
Expand file tree
/
Copy path061-Remove-Element-from-List.py
More file actions
80 lines (64 loc) · 2.73 KB
/
Copy path061-Remove-Element-from-List.py
File metadata and controls
80 lines (64 loc) · 2.73 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""
===============================================================================
File Name : 61-Remove-Element-from-List.py
Description : Remove an Element from a List in Python
Author : Shaik Mahaboob Basha
===============================================================================
Definition:
The remove() method is used to remove the first occurrence of a specified
element from a list.
Syntax:
list_name.remove(element)
Example:
numbers.remove(30)
"""
# -----------------------------------------------------------------------------
# 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()
# -----------------------------------------------------------------------------
# Removing the element 30 from the list.
# -----------------------------------------------------------------------------
numbers.remove(30)
# -----------------------------------------------------------------------------
# Displaying the updated list.
# -----------------------------------------------------------------------------
print("After Removing 30 :", numbers)
# Output:
# After Removing 30 : [10, 20, 40, 50]
print()
# -----------------------------------------------------------------------------
# Removing the first element from the list.
# -----------------------------------------------------------------------------
numbers.remove(10)
# -----------------------------------------------------------------------------
# Displaying the updated list.
# -----------------------------------------------------------------------------
print("After Removing 10 :", numbers)
# Output:
# After Removing 10 : [20, 40, 50]
print()
# -----------------------------------------------------------------------------
# Removing the last element from the list.
# -----------------------------------------------------------------------------
numbers.remove(50)
# -----------------------------------------------------------------------------
# Displaying the updated list.
# -----------------------------------------------------------------------------
print("After Removing 50 :", numbers)
# Output:
# After Removing 50 : [20, 40]
print()
# -----------------------------------------------------------------------------
# Displaying the total number of elements in the list.
# -----------------------------------------------------------------------------
print("Total Elements :", len(numbers))
# Output:
# Total Elements : 2