sum of first and last element of a list in Python
Hello guys this is Satyam gain back with another awesome blog and in this blog I am going to show you how you can find the sum of the first and last element of a list in Python.But If you don't know about Lists you can check out our Tutorial on it.
So the first step will be creating a list.
my_list = [2,3,8,10]
So you can see above that I have created a list in Python with some random values.
Now we are moving into the main part of this blog, i.e. finding the sum of the first and the last element.
l = len(my_list)
sum = my_list[0] + my_list[l-1]
print(sum)
The above code will give the output 12 as 10 + 2 is 12..
Thanks for Reading
No comments: