Harri Hämäläinen 1. Answer each of the following questions with a few sentences. (a) Why do you think Python developers chose to make instances of types str and tuple immutable? Some suggestions: - immutable types can be used in places, where mutable types such lists are not allowed, such as keys for dictionary - performance, the size of the immutable object cannot change during run time Grading: +1 point / valid reasoning, 2 points at maximum (b) When should some functionality be provided by functions and when by classes and their methods? Some suggestions: - classes are often used to model some state of your program, methods in classes are one way to change that state - operations which don't affect to the state of program are usually better to be implemented as functions, if their functionality is not related to any of your classes Grading: +1 point if told when to use functions, +1 point if told when to use methods (c) What are the main differences and commonalities between the containers dict and list? Some suggestions: - lists and dicts both support iteration - both are mutable - dict is a key-value mapping where items are accessed by the key - list is a positionally ordered container where items are accessed by the index Grading: +0.5 / valid (difference | commonality), rounded up (d) Why is the Method Resolution Order (MRO) needed in Python? Some suggestions: - MRO defines the order in which base classes are visited when call for some attribute occurs - when multiple inheritance is used, basic bottom-up approach might cause ambiguous results - better be explicit! Grading: +1 point if just given the reason without any explanation, +1 point if answer also shows an example of case when it's needed or describes how MRO finds the correct definition