how to get the first element in a list in python code example

Example 1: find the first element in phython list

Alist = ['Sun','Mon','Tue','Wed','Thu']
print("The given list : ",Alist)

print("The first element of the list : ",Alist[0])
print("The last element of the list : ",Alist[-1])

Example 2: 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 3: how to find first value of an list

// Python
list = [1,2,3]
firstdigit = list[0] // 1 

list = ['Hello', 'bye', 'Adios']
firstvalue = list[0] // 'Hello'

Tags:

Java Example