how we can get first value from list in python code example

Example 1: 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))

Example 2: how to find first element in a list python

an_array = [1,2,3,4,5]
first element = an_array[0]

Tags:

Php Example