mathielo
0
Q:

how to print last element in a list python

some_list = [1, 2, 3]
some_list[-1]
print(some_list)
#Output = 3
1
lis[len(lis)-1]
1
# Python3 code to demonstrate  
# to get first and last element of list 
# using list indexing 
  
# initializing list  
test_list = [1, 5, 6, 7, 4] 
  
# printing original list  
print ("The original list is : " +  str(test_list)) 
  
# using list indexing 
# to get first and last element of list 
res = [ test_list[0], test_list[-1] ]  
  
# printing result 
print ("The first and last element of list are : " +  str(res)) 
3
your_list = ["apple", "orange", "grapes"]
last_value = your_list[-1]
1

New to Communities?

Join the community