Answers for "how to get list elements in python [-1]"

5

python get first element in a list

# 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))
Posted by: Guest on April-13-2020
1

how to index lists in python

# Make the list
list = ['bananas', 'apples', 'watermellon']
# Print the word apples from the list
print(list[1])
Posted by: Guest on March-29-2020

Code answers related to "how to get list elements in python [-1]"

Python Answers by Framework

Browse Popular Code Answers by Language