3) e. Tuples Examples




Enrico has been noticing that dictionaries are cool, however, he feels they are not as safe since anyone can change, remove or add keys and values. He wants something more robust. Show to Enrico how a tuple is written in Python by using few elements.

1
2
Output:
('leaf', 'mow', 'mailbox', 'cork', 'wood')




Pyetra has created a huge tuple and cannot remember what was its first two elements. Help Pyetra retrieve those by slicing her tuple to obtain elements with index 0 and 1.

1
2
3
Output:
('hat', 'bath towel', 'glove', 'cattle', 'pet', 'scarf')
My first two items =  ('hat', 'bath towel')




Enrico is now jealous of Pyetra’s long tuple and proposes her to merge the two tuples into one. Is this possible? Try it: create a new tuple that is the sum of another two.

1
2
Output:
('leaf', 'mow', 'mailbox', 'cork', 'wood', 'hat', 'bath towel', 'glove', 'cattle', 'pet', 'scarf')