Program:
def secLargestNum(list1):
#Sorting the list in ascending order
list1.sort()
#Returning the second last index of list1
#List with negative indexing will start from the end in reverse order with -1 as
the index of the last element
secondLast = list1[-2]
#or len(list1)-2 can be used which will return second last element
#secondLast = list1[len(list1)-2]
return secondLast
list1 = [1, 2, 3, 4, 5, 6, 7, 8, 9]
#Using secLargestNum function to get the function
sec_num = secLargestNum(list1)
#Printing all the elements for the list
print("The elements of the list",list1)
#Printing the second largest num
print("\nThe second-largest number of the list:",sec_num)
OUTPUT:
The elements of the list [1, 2, 3, 4, 5, 6, 7, 8, 9]
The second-largest number of the list: 8