Tuple assignment
tup = (3,'xyz',[1,2,3]) ind, myKey, myList = tupThis is called unpacking. It is wise to do this only on tuples since they are immutable and it is sure that the number of elements being unpacked is same as the number of variables on the left side. This can be very useful when using *args and **kwargs. More on that later.
Use negative index
myList[-1] returns the last element
No comments:
Post a Comment