Question: Time left 0 : 3 3 : 5 8 Hide Information Flag question Information text SECTION A: SHORT QUESTIONS ( 2 0 MARKS ) Information

Time left 0:33:58
Hide
Information
Flag question
Information text
SECTION A: SHORT QUESTIONS (20 MARKS)
Information
Flag question
Information text
Question 1(20 marks)
Question 1
Answer saved
Flag question
Question text
1.1. Explain the difference between a list and a tuple in Python, including their key characteristics and when you would use one over the other (5 marks)
Answer text Question 1
Rich text editor
Lists are objects that contain multiple data items, data in lists can be changed as lists are mutable. they are dynamic structures because items can be removed and added from them. Each itme stored in a list is called an element.
A Tuple is immutable, as the contents cannot be changed. once it is created no changes can be made.
Question 2
Answer saved
Flag question
Question text
1.2. Describe how inheritance works in Object-Oriented Programming (OOP) and provide an example of how it could be applied to reuse code in Python (5 marks)
Answer text Question 2
Rich text editor
Inheritance is a relationship, the relationship allows a class to inherit properties and behaviours from another class. this means you can define common features in a parent class and let the child class reuse them. if you have a general Animal class with attributes like age and methods like speak. you can create child classes like dog or cat that inherit these features. each child class can have its own unique behaviour while still sharing the functionality of the Animal class.
Question 3
Answer saved
Flag question
Question text
1.3. Define a dictionary in Python and demonstrate how you can add, retrieve, and delete items from a dictionary

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!