Python: last element of tuple
python, tuples
Solution
What you are trying to do is impossible. Those two fives are exactly the same.
However, when iterating over the tuple you can check if you reached the last element like this:
a = (3, 5, 5)
for i, var in enumerate(a):
if i == len(a) - 1:
print 'last element:'
print var
Demo:
In [1]: a = (3, 5, 5)
In [2]: for i, var in enumerate(a):
...: if i == len(a) - 1:
...: print 'last element:'
...: print var
...:
3
5
last element:
5
Problem
I would isolate the last element of a tuple like ``` a = (3,5,5) last = a[-1] ``` but the problem is that i have a pice ok code like this ``` if var == last: do something ``` and it takes the first `5` and not the second, how can i do to take the last one?