+ 5
how do you access the last element of the tuple: A=(0,1,2,3) :
Write a code and please explain.
4 odpowiedzi
+ 3
Use negative indexing
A=(1,2,3)
Print (A[-1])
Output 3
It will return last element
Print(A[-2])
Output 2
It will return second last element of tuple
+ 4
A[-1]
+ 1
In tuple A if u want to access last element then u have to write like this
A[-1] this represent last element
If u want to access second last them
A[-2] it will print 2 for first one from last A[-3]
..... Similar for more element Start from -1 and do incremet by -1
0
A[-1]