Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

remove last element from list python

# 3 ways to remove last element from list python
# program to delete the last
# last element from the list 
#using pop method

list = [1,2,3,4,5]
print("Original list: " +str(list))

# call the pop function
# ele stores the element 
#popped (5 in this case)
ele= list.pop()

# print the updated list
print("Updated list: " +str(list))

# slice the list 
# from index 0 to -1
list = list[ : -1]

# print the updated list
print("Updated list: " +str(list))

# call del operator
del list[-1]

# print the updated list
print("Updated list: " +str(list))
Source by www.howtouselinux.com #
 
PREVIOUS NEXT
Tagged: #remove #element #list #python
ADD COMMENT
Topic
Name
1+5 =